Boost logo

Boost :

Subject: Re: [boost] [Locale] Preview of 3rd version
From: Artyom (artyomtnk_at_[hidden])
Date: 2010-09-12 09:13:47


>
> On 12/09/2010 11:32, Artyom wrote:
> >> 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.
> >
> > C++0x char16_t and char32_t are define as
> >
> >> Types _Char16_t and _Char32_t denote distinct types with the same size,
> >> signedness,
>
> That's not how it is in C++0x.
> char16_t and char32_t are directly keywords, which has the bad effect or
> preventing you from defining types with such names.
>
> >>
> >> and alignment as uint_least16_t and uint_least32_t,
> >> respectively, in<stdint.h>, called the underlying types.
> >
> > So no problems there,
>
> Yes there are.
> It has nothing to do with size and alignment. It's different types, so
> the compiler is allowed to assume the memory doesn't alias so that it
> can do smart optimizations.
>
> If you compile your code with -Wstrict-aliasing with GCC, you will get a
> warning that says so.
>

1st it don't warns,

But anyway there is not problem as
I don't relay on strict aliasing as I convert pointers to other ones with
compatible
types and then forward them to appropriate function.

I don't do stuff like this:

   wchar_t buf[2] = { a, b };
   uint16_t *ptr = buf;
   foo(ptr);

   return buf[0]; // which may be dangerous

I cast these pointers and to apropriate uintXX_t type and use only them:

   ptr[0]; // ok

Without this casts the code would be much bigger and complicated.
So when you use them with care, no problems should be.

These casts use me to detach from original types and go other
well defined types with known signess and size.

Thanks for the point, I wasn't fully aware of this.

Artyom

      


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