
3 Jan
2011
3 Jan
'11
4:01 p.m.
At Mon, 03 Jan 2011 00:08:23 -0800, Patrick Horgan wrote:
I'm not so sure. This idiom has been around as long as unions were in C. Do you know of any compilers that don't support it? Of course memcpy or any other solution using character pointers would be supported, but compilers wouldn't generate efficient code for in this case a simple swap of 16 bit ints. Clearly the specs say that a union can only contain one object at a time. Hmmm. The C99 spec has a footnote to section 6.5.2.3/3 that seems to clearly say you can do this
The C99 spec is irrelevant to C++; it isn't even "included by reference," as the C89 spec is. -- Dave Abrahams BoostPro Computing http://www.boostpro.com