From: Frank Mori Hess (frank.hess_at_[hidden])
Date: 2007-10-03 09:00:16
-----BEGIN PGP SIGNED MESSAGE-----
On Tuesday 02 October 2007 17:47 pm, Stefan Seefeld wrote:
> Sebastian Redl wrote:
> > Marco wrote:
> >> Are you speaking about rules provided in the C++ ISO standard ? Could
> >> you point me to them ? (page, section). I'd like to give them a look .
> > Reinterpret_cast is defined in 5.2.10. The language there is rather
> > clear about what is guaranteed and what not. Judging by that section,
> > you can't rely on the results of the cast for anything except casting it
> > back.
> Yes. To give a practical example: GCC will complain about invalid type
> casts, since they break its ability to optimize based on proper alias
> analysis. The issue is not about layout compatibility, but the compiler's
> ability to infer whether two pointers may refer to the same address.
> If their types differ, they may not, in general.
Yes, as I learned once by trying to change the byte-ordering of floats by
manipulating them through a uint32_t*, once your turn optimization on your
code breaks badly. The only exception is that char* is allowed to alias with
anything (don't think you can bounce a pointer through a char* into something
else though). gcc allows (as an extension) using a union to access the same
chunk of data a more than one type. See
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
-----END PGP SIGNATURE-----
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk