Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C locale questions

Tags:

c

locale

I have some questions, but I can´t find straight answer anywhere.

So, basically, I know what locale is, I know how to use (set) it, but what I dont know is

  1. how is work behind the scene, and I would very like to know it. So, when I use functions for IO, lets say for example scanf do float, when I need to decide whether country use decimal point or comma (I am actually from decimal comma country :)),

  2. does scanf function "look" to check the current locale?

  3. But if I doesn´t set it in my code, does it by default creates some standard locale itself, OR does it get it from OS?

  4. For example in the part of code when you get handle to console for stdout stderr and stdin?

like image 406
B.Gen.Jack.O.Neill Avatar asked Jul 27 '11 14:07

B.Gen.Jack.O.Neill


1 Answers

By default your program will have the C locale.

When you run setlocale(LC_ALL,""); you will set the locale from the outside environment (or you can set just parts LC_*).

By calling setlocale(LC_ALL,"specific_locale"); you will set the specific locale.

All I/O functions should follow the current locale (standard C I/O functions).

The behind-the-code behaviour depends on the operating system and compiler you are using.

like image 78
Šimon Tóth Avatar answered Sep 29 '22 00:09

Šimon Tóth