public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Locales
@ 2006-05-13 10:19 chris
  2006-05-13 10:35 ` Locales Brian Dessent
  0 siblings, 1 reply; 2+ messages in thread
From: chris @ 2006-05-13 10:19 UTC (permalink / raw)
  To: gcc-help

Hi,

I have the following code that is supposed to print the name of the native locale:

#include <locale>
#include <iostream>

int main(int argc, char **argv)
{
    std::locale test("");    
    std::cout << "Native Locale is: " << test.name() << std::endl;
    return 0;
}

The above code on Windows with Visual Studio 7 shows:

Native Locale is: English_United_Kingdom

or something very close to that. Using gcc on Windows (MinGW's g++) it shows:

Native Locale is: C

which is relatively sensible, but using gcc (g++) on Linux I get:

Native Locale is: LC_TYPE=en_GB.UTF-8;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C; LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C; LC_MEASUREMENT=C;LC_IDENTIFICATION=C

when what I expected was:

Native Locale is: en_GB.UTF-8

or something similar. Now, I could extract the native locale from the LC_TYPE variable, but I wondered:

1) Was the list of locale LC_ variables something you would have expected?
2) Is there something else I should be constructing the locale with to give the native locale on Linux?
3) Is it possible to get the correct native locale on Windows with gcc (rather than C - the same results if I build and run the program in MSYS or the Windows Command Prompt)? Any answer to question 2 may answer this, I guess.

Thanks for any help you can give.

Chris


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Locales
  2006-05-13 10:19 Locales chris
@ 2006-05-13 10:35 ` Brian Dessent
  0 siblings, 0 replies; 2+ messages in thread
From: Brian Dessent @ 2006-05-13 10:35 UTC (permalink / raw)
  To: gcc-help

chris@blueband.demon.co.uk wrote:

> 1) Was the list of locale LC_ variables something you would have expected?
> 2) Is there something else I should be constructing the locale with to give the native locale on Linux?
> 3) Is it possible to get the correct native locale on Windows with gcc (rather than C - the same results if I build and run the program in MSYS or the Windows Command Prompt)? Any answer to question 2 may answer this, I guess.

Mingw is only reporting what the locale is set to in the environment,
which in this case means that you don't have the environment variable
LANG or LC_ALL (or any of the other LC_*) set.  On linux it is very
likely that these are initialized for you in one of the stock profile/rc
files, but there is no such thing in the default mingw/MSYS rc files, so
you should add this if you want that behavior.  It is not the job of the
STL or the compiler to set these variables, merely to act on how they
are set by the user, or in the case of them not being set to use the
default "C" locale.

I think the question you're really asking is, "Is there any mechanism
for the locale as set in Windows to be reflected in the environment
variables LANG/LC_*?" and I think the answer to that is no, they work
differently and need to be set independantly.  But I could be wrong.

Brian

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-05-13 10:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-05-13 10:19 Locales chris
2006-05-13 10:35 ` Locales Brian Dessent

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).