Skip to content
Search

Clocale

lastmod 2018-08-17created 2015-05-078 edits

The C language supports localization specific settings, such as culture-specific date formats or country-specific currency symbols.

Category

MBCS vs WCS

This page looks at conversion between character sets. String type conversion is easy to think of as simply converting between char and wchar_t, but you must keep the concept of character sets in mind.

  • MBCS is not a single encoding.
  • The data type that holds MBCS is char
  • UTF-8 is also stored in char, just like MBCS.
  • Wide Char is a single encoding scheme. (UTF-16 or UTF-32 depending on the compiler)
  • Wide Char is stored in wchar_t.
  • In other words, wchar_t holds only strings encoded in UTF-16 or UTF-32.

LC Category

=== LANG=C === In conclusion, setting LANG to "C" means turning off the locale, and "C" is indeed a locale name defined in the standard.

The locale name is "C" because it is specified as follows in 7.11.1.1 The setlocale function of the C language standard. (It seems to be "C" because it comes from the C language standard)

"A value of "C" for locale specifies the minimal environment for C translation;"

Simple Example

#include <stdio.h>
#include <stdlib.h>
#include <locale.h>

int main(void)
{
    /* Locale is set to "C" before this. This call sets it
       to the "current locale" by reading environment variables: */
    setlocale(LC_ALL, "");

    const struct lconv * const currentlocale = localeconv();

    printf("In the current locale, the default currency symbol is: %s\n",
        currentlocale->currency_symbol);

    return EXIT_SUCCESS;
}

See also

Favorite site

MSDN

References


  1. Using_UTF-8_as_the_internal_representation_for_strings_in_C_and_C++_with_Visual_Studio-Nubaria_Blog.pdf ↩