Boost logo

Boost :

Subject: Re: [boost] [Locale] Preview of 3rd version
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2010-09-11 21:02:22


On 11/09/2010 21:10, Artyom wrote:

> Take a look on my code, I don't update from_next till I write both surrogates,
> just sometimes I write them separately as usually uto + 1 == uto_end in
> MSVC implementation.

Woah, I wonder how I didn't catch that one before!
I never really checked for the size of uto because my converters do not
support checking the size of the ouput since that's normally a waste of
time.

But then it can't use max_length because that's for the other way
around. I really wonder why they didn't make codecvt symmetric.

> So technically your code is wrong as you write into position of uto_end
>

Indeed, thanks for elucidating that mystery for me.

> I use uint16_t cast when sizeof(wchar_t) == 2 and uint32_t cast when sizeof of
> wchar_t == 4, I don't
> see any problem with this.

According to the C++ standard, it is illegal for pointers of different
types to reference the same memory location, with a few exceptions:
- char* may safely alias any object
- signedness and cv qualifications don't count as a different type with
regards to that rule.

Unfortunately, wchar_t is a different type from uint16_t or uint32_t, so
what you are doing probably counts as breaking the strict aliasing rule.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk