C localization functions: Difference between revisions

Content deleted Content added
Tag: Reverted
Rescuing 2 sources and tagging 0 as dead.) #IABot (v2.0.9.5
 
(One intermediate revision by one other user not shown)
Line 6:
==Overview of functions==
 
C localization functions and types are defined in {{mono|locale.h}} ({{mono|clocale}} header in C++).<ref name=www.utas.edu.au>{{cite web|title=locale.h|url=http://www.utas.edu.au/infosys/info/documentation/C/CStdLib.html#locale.h|work=utas.edu.au|publisher=infosys|accessdate=14 September 2011|archive-date=4 June 2012|archive-url=https://web.archive.org/web/20120604201614/http://www.utas.edu.au/infosys/info/documentation/C/CStdLib.html#locale.h|url-status=dead}}</ref><ref>{{Cite web|url=https://github.com/openbsd/src/blob/master/include/locale.h|title=openbsd/src|website=GitHub|language=en|access-date=2018-04-09}}</ref>
 
{| class="wikitable" style="font-size:0.85em;"
Line 22:
==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.<ref>{{cite web | title=The Standard C Locale and the Standard C++ Locales | url=http://www.math.hkbu.edu.hk/parallel/pgi/doc/pgC++_lib/stdlibug/sta_9169.htm | publisher=Rogue Wave Software, Inc. | year=1996 | access-date=10 November 2011 | archive-date=19 February 2020 | archive-url=https://web.archive.org/web/20200219173855/http://www.math.hkbu.edu.hk/parallel/pgi/doc/pgC++_lib/stdlibug/sta_9169.htm | url-status=dead }}</ref>
 
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==
//name of programmer
<syntaxhighlight lang="c">
#include <stdio.h>