On 20 June 2007 11:36, Bokhanko, Andrey S wrote:

> Hi,
> 
> As I learned from experience, gcc always assume independence between memory
> references in the following program: 
> 
> typedef struct {
>     int m1;
>     int m2;
> } S1;
> 
> void foo(S1 *p1, S1 *p2) {
>     ... = p1->m1;
>     ... = p2->m2;
> }
> 
> ...even if -fno-strict-aliasing (an option disabling ansi-aliasing rules)
> supplied. 
> 
> I wonder, is there a way to force gcc not to assume independence in the
> example shown above? 

  Just maybe if you give the struct definition __attribute__ ((packed)) gcc
will no longer assume that all struct S1s are naturally aligned and therefore
know that they might overlap?  (But it's also quite possible that it won't...
I haven't been through the sources to determine how much aliasing information
it infers from alignment.)

    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....

Reply via email to