Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

memcpy vs. gcc strict aliasing

On Tue, 02 Dec 2008, David Laight wrote:
> Recent versions of gcc will treat the memcpy the same as the structure
> assignment! This means both 'suffer' from the 'strict aliasing'
> optimisations.

The part of the C99 standard that gives the aliasing rules (section 6.1
paragraph 7 in the N1256 draft) allows any object to be accessed through
a character type.  I'd argue that the text "the memcpy function copies
n characters ..." in the definition of the memcpy function (section of the N1256 draft) means that memcpy is supposed to do its
work using character types (even though the args are passed as void*
pointers).  Given the implied use of character types, it seems to me
that the use of memcpy should not lead to surprises traceable to the
aliasing rules.  If the use of memcpy is leading to aliasing surprises,
I'd argue that there's a compiler bug.

--apb (Alan Barrett)

Home | Main Index | Thread Index | Old Index