This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Strict Aliasing document


On 01/04/2011 09:18 PM, Patrick Horgan wrote:
On 01/04/2011 05:44 AM, Andrew Haley wrote:
On 12/31/2010 09:04 AM, Patrick Horgan wrote:
Some time ago I asked for reviews of a white paper on strict aliasing and the confusions people have about it, on this mailing list and got some great comments. I've rewritten the paper in response to the comments and would love it if people would read it and give MORE comments about ways to improve it. The intent is to provide something that I can refer people to when the issue comes up each time. The document is :

http://dbp-consulting.com/StrictAliasing.pdf

This link is broken.


Andrew.

I just did: wget http://dbp-consulting.com/StrictAliasing.pdf

and it came down fine.

I got it now.


You're wrong about using memcpy(): in many cases gcc will elide calls
to memmcpy(), and indeed it does in your example!  There's no reason
to assume that the union version will always be faster.

It'd be better to define swapem as

typedef union {
    uint32_t as32bit;
    uint16_t as16bit[2];
} swapem;

which is standard in C and C++.

It's worth saying that just about every compiler supports type-punning
through a union, but it is *not* guaranteed by any standard.

Nice job.

Andrew.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]