Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > the relation between C++ locale and C locale

Reply
Thread Tools

the relation between C++ locale and C locale

 
 
zade
Guest
Posts: n/a
 
      03-05-2010
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?
 
Reply With Quote
 
 
 
 
James Kanze
Guest
Posts: n/a
 
      03-05-2010
On 5 Mar, 03:45, zade <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the difference and relation between an interface and itsmethod? tenxian Java 4 04-27-2008 06:26 PM
Relation between Interface and Area for OSPF winds Cisco 1 02-10-2006 08:41 AM
relation between typeid and typeinfo class (related by friend ?) Ganesh C++ 3 05-10-2005 09:53 AM
i18n problem, involving Locale.getDisplayLanguage and Locale.getDisplayCountry Maurice Hulsman Java 1 07-25-2004 06:11 PM
what is the relation between HTTPServletResponse setContentLength header and keep-alive Naresh Agarwal Java 1 05-29-2004 10:01 AM



Advertisments