Re: codecvt problem
On 2011-06-17 05:42, Ulrich Eckhardt wrote:
According to my manpage of mbstate_t, you _must_ initialize it using
memset(). That means that any implementation defining it as a pointer must
not actually read it as a pointer, but only use access variants like
memcpy(), memcmp() etc.
An implementation may guarantee further details and rely upon others that
the language standard does not, so I guess in that case the implementation
relies either on the fact that all-bits-zero is actually a null pointer,
or on the fact that mbstate_t is not a pointer, and guarantees that memset
will work. It's hard for me to imagine such an implementation that defines
mbstate_t as a pointer and bothers to access the value only through memcpy,
memcmp, etc., though one is possible.
I think it's a defect in the language standard (probably that of C) that
it mentions "an initial conversion state" several times but fails to
provide a means to achieve one. All the C standard says is:
"A zero-valued mbstate_t object is (at least) one way to describe
an initial conversion state." (7.24.6/3)
The language standard should have provided an initializer, or specified
further on what types mbstate_t could be so that more explicit forms of
initializers could be used.
This means that all "clean" initialisations
mentioned in this thread (e.g. "mbstate_t s = {};" or "mbstate_t s =
mbstate_t();") are actually not guaranteed to work.
I cannot understand why not. Can you explain it further?
--
Seungbeom Kim
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]