On Tue, Jun 7, 2011 at 4:31 PM, Jonathan Wakely <jwakely....@gmail.com> wrote: > On 7 June 2011 15:20, Richard Guenther wrote: >>> >>> However, for my construct, which appears to be completely legal, I get a >>> warning, which I'd like to disable. How can I do that? Currently I'm using >>> -Wno-strict-aliasing, but I'd like to have a better solution. I tried to >>> cast (void*) before the cast to (OBJECT*), it didn't help. Is it possible >>> to disable this warning for this line only (maybe with some GCC specific >>> tricks)? >> >> Try >> >> void *temp = (void *)data; >> reinterpret_cast<int *>(temp) > > Should that be static_cast not reinterpret_cast? > > A reinterpret_cast from void* is technically undefined in C++03, see > http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1120 and > http://homepage.ntlworld.com/jonathan.deboynepollard/FGA/reinterpret-cast-and-pointer-to-void.html > > Although GCC will do the right thing, if a static_cast will suffice > then it should generally be preferred to reinterpret_cast.
I thought static_cast might do pointer adjustments while reinterpret_cast will never do that but is value-preserving. Richard.