memcpy / Language Lawyer / optimization question
Paul Jarc
prj@po.cwru.edu
Thu Dec 9 19:52:00 GMT 2004
Joe Buck <Joe.Buck@synopsys.COM> wrote:
> On Thu, Dec 09, 2004 at 11:32:55AM -0800, Steve Ellcey wrote:
>> I have a question about memcpy and when it is legal to turn it into a
>> simple assignment. The first memcpy in the program below will cause an
>> abort on IA64 when compiled with -O2 because it gets turned into integer
>> assignment and p is not properly aligned. I think this is OK.
>
> No, it's not OK; you are lying to the compiler and paying for the offense.
I think he's saying the crash is ok in this case, not the code.
> By declaring the return value of foo to be a pointer to int, you are
> promising that the return value will be aligned. It isn't, therefore you
> get a crash.
Is it expected that a (char*) cast avoids the crash, while a (void*)
cast does not?
paul
More information about the Gcc
mailing list