the relation between C++ locale and C locale

Discussion in 'C++' started by zade, Mar 5, 2010.

  1. zade

    zade Guest

    C has its locale function, and C++ has its locale class. When used, I
    don't know their relation. For example , what is the diff for the
    codes below:

    std::locale::global(std::locale(""));
    std::setlocale(LC_ALL,"");

    in GNU C++(http://gcc.gnu.org/onlinedocs/libstdc /manual/
    locales.html#manual.localization.locales.locale), it says:

    From Josuttis, p. 697-698, which says, that "there is only *one*
    relation (of the C++ locale mechanism) to the C locale mechanism: the
    global C locale is modified if a named C++ locale object is set as the
    global locale" (emphasis Paolo), that is:

    std::locale::global(std::locale(""));

    affects the C functions as if the following call was made:

    std::setlocale(LC_ALL, "");

    On the other hand, there is *no* vice versa, that is, calling
    setlocale has *no* whatsoever on the C++ locale mechanism, in
    particular on the working of locale(""), which constructs the locale
    object from the environment of the running program, that is, in
    practice, the set of LC_ALL, LANG, etc. variable of the shell.


    But in my experience, it is not the same as in windows system.
    So what their relation?
     
    zade, Mar 5, 2010
    #1
    1. Advertising

  2. zade

    James Kanze Guest

    On 5 Mar, 03:45, zade <> wrote:
    > C has its locale function, and C++ has its locale class. When
    > used, I don't know their relation. For example , what is the
    > diff for the codes below:


    > std::locale::global(std::locale(""));
    > std::setlocale(LC_ALL,"");


    > in GNU C++(http://gcc.gnu.org/onlinedocs/libstdc /manual/
    > locales.html#manual.localization.locales.locale), it says:


    > From Josuttis, p. 697-698, which says, that "there is only
    > *one* relation (of the C++ locale mechanism) to the C locale
    > mechanism: the global C locale is modified if a named C++
    > locale object is set as the global locale" (emphasis Paolo),
    > that is:


    > std::locale::global(std::locale(""));


    > affects the C functions as if the following call was made:


    > std::setlocale(LC_ALL, "");


    > On the other hand, there is *no* vice versa, that is, calling
    > setlocale has *no* whatsoever on the C++ locale mechanism, in
    > particular on the working of locale(""), which constructs the
    > locale object from the environment of the running program,
    > that is, in practice, the set of LC_ALL, LANG, etc. variable
    > of the shell.


    > But in my experience, it is not the same as in windows system.
    > So what their relation?


    Vague. In fact:

    -- std::local::global is guaranteed to call setlocale if the
    locale is named. If the locale is not named, the behavior
    is implementation defined.

    -- Strictly speaking, setlocale is not allowed to influence
    std::locale, since "No library function other than
    locale::global() shall affect the value returned by
    locale()", and setlocale is a library function. In
    practice, I'm not sure that this was intended.


    Practically speaking, implementations which use an existing C
    library for setlocale, without modifying it, cannot have
    setlocale modify the global locale, and probably can't do an
    effective setlocale if the locale is not names. Other
    implementations can do the right thing, however, and keep the
    two locales in sync; this is what I would expect from a quality
    implementation in cases where the implementors of the C++
    library have some control over the C library.

    --
    James Kanze
     
    James Kanze, Mar 5, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Naresh Agarwal
    Replies:
    1
    Views:
    1,100
    ExGuardianReader
    May 29, 2004
  2. Ganesh
    Replies:
    3
    Views:
    509
    Rolf Magnus
    May 10, 2005
  3. Satya
    Replies:
    1
    Views:
    1,267
    jmcgill
    May 16, 2006
  4. giodo
    Replies:
    0
    Views:
    454
    giodo
    Oct 10, 2007
  5. tenxian
    Replies:
    4
    Views:
    284
    Mark Space
    Apr 27, 2008
Loading...

Share This Page