This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: memcpy / Language Lawyer / optimization question
- From: Paul Schlie <schlie at comcast dot net>
- To: <gcc at gcc dot gnu dot org>
- Date: Thu, 09 Dec 2004 17:54:08 -0500
- Subject: Re: memcpy / Language Lawyer / optimization question
> Joseph S. Myers wrote:
>> 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.
As a more general but related question: as C does not define/specify
everything, and even occasionally specifies something as being explicitly
"unspecified", giving license to the complier to express whatever incidental
behavior it may have; has the GCC team adopted the strategy that it will
strive to adopt and document the behavior which seems most generally useful
and/or least-fragile in such circumstances (which it has license to do), as
opposed to justifying any such behavior as being "legal" without regard to
the consideration of adopting a more useful behavior, and/or emit warnings
if the adopted behavior may have undesirable consequences when reasonable
to do so; or is this also "unspecified"? :)