memcpy / Language Lawyer / optimization question
Joseph S. Myers
joseph@codesourcery.com
Thu Dec 9 20:20:00 GMT 2004
On Thu, 9 Dec 2004, Steve Ellcey wrote:
> My question is about the second memcpy where I cast to (void *). This
> still results in an abort on IA64 because it is still assuming integer
> alignment (and thus changing the code to do an integer assignment). Is
> it legal to do this transformation with the (void *) cast?
The casts in the calls to memcpy are irrelevant: the undefined behavior
occurs before them, at the point where you cast an unaligned pointer to
int *. Casting a pointer to another pointer type for which it doesn't
have the alignment yields undefined behavior. The compiler can assume
that the result of a sequence of pointer casts has the alignment of
whichever type in the sequence of pointer types has the strictest
alignment requirements.
--
Joseph S. Myers http://www.srcf.ucam.org/~jsm28/gcc/
jsm@polyomino.org.uk (personal mail)
joseph@codesourcery.com (CodeSourcery mail)
jsm28@gcc.gnu.org (Bugzilla assignments and CCs)
More information about the Gcc
mailing list