New Locale-dependent C Runtime Functions

New Locale-dependent C Runtime Functions

  • Comments 2

In "POSIX" style locale support on Windows?, Michael Kaplan, the Technical Lead for Windows Globalization, describes the existing locale-dependent functions in the C Runtime (CRT) as "unwieldy". To compare strings, for example, using a different locale than is currently set for the process or thread you must call setlocale() to set the desired locale and to get the old locale, call the function or functions, then call setlocale() again using the old locale. Someone Michael mentions in his blog suggests that locale-dependent functions should accept a locale instead, like the managed String.Compare() method.

The CRT shipping with Whidbey adds that capability using the new locale-dependent functions that are similar to the old functions, but end in _l and accept a parameter of type _locale_t, like _stricmp_l(). As an alternative to setting and resetting the process or thread locale, you can create and store a _locale_t variable returned from _create_locale() that accepts the same parameters as setlocale(). When appropriate, the Secure CRT functions - similar in nature to the functionality that strsafe.h provides - are defined to accept a locale, like strncpy_s_l().

Leave a Comment
  • Please add 5 and 8 and type the answer here:
  • Post
  • This is great info. Thanks for posting about it!

    Although I wonder how portable they are -- are they widely supported?
  • I did an MSN Search originally which yielded no results. I had to search (knowing this information was available publicly) to find them since the robots.txt file denies indexing for crawlers. Based on that, it appears that they are our extensions. Hopefully this will set a new standard of locale-dependent functions, though.
Page 1 of 1 (2 items)