
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 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 http://mail-index.netbsd.org/tech-kern/2003/08/11/0001.html - -- Frank -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFHA5Jj5vihyNWuA4URAhYDAKCfTGJaBkE83UuGouCR1gKujRsPsgCfcKkC 0J8bm7kqPcHfCVoNfXYuztg= =Dl7P -----END PGP SIGNATURE-----