C localization functions explained

In computing, C localization functions are a group of functions in the C programming language implementing basic localization routines.[1] [2] The functions are used in multilingual programs to adapt to the specific locale. In particular, the way of displaying of numbers and currency can be modified. These settings affect the behaviour of input/output functions in the C Standard Library.[3]

Overview of functions

C localization functions and types are defined in (header in C++).[4] [5]

FunctionDescription
setlocalesets and gets the current C locale
localeconvreturns numeric and monetary formatting details of the current locale

Criticism

C standard localization functions are criticized because the localization state is stored globally. This means that in a given program all operations involving a locale can use only one locale at a time. As a result, it is very difficult to implement programs that use more than one locale.[6]

The functions alter the behavior of printf/scanf/strtod which are often used to write saved data to a file or to other programs. The result is that a saved file in one locale will not be readable in another locale, or not be readable at all due to assumptions such as "numbers end at comma characters". Most large-scale software forces the locale to "C" (or another fixed value) to work around these problems.

Example

  1. include
  2. include
  3. include

int main(void)

See also

Notes and References

  1. Book: ISO/IEC 9899:1999 specification . p. 204, ยง 7.11 Localization .
  2. Book: Prata, Stephen . C primer plus . 2004 . Sams Publishing . 0-672-32696-5 . Appendix B, Section V: The Standard ANSI C Library with C99 Additions.
  3. Web site: ISO/IEC 9899:201x. 12 April 2011. 181. https://web.archive.org/web/20180329042731/http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf. 29 March 2018.
  4. Web site: locale.h. utas.edu.au. infosys. 14 September 2011. 4 June 2012. https://web.archive.org/web/20120604201614/http://www.utas.edu.au/infosys/info/documentation/C/CStdLib.html#locale.h. dead.
  5. Web site: openbsd/src. GitHub. en. 2018-04-09.
  6. Web site: The Standard C Locale and the Standard C++ Locales . Rogue Wave Software, Inc. . 1996 . 10 November 2011 . 19 February 2020 . https://web.archive.org/web/20200219173855/http://www.math.hkbu.edu.hk/parallel/pgi/doc/pgC++_lib/stdlibug/sta_9169.htm . dead .