Clarification anyone? -- was Re: Linux and aliasing?

James Antill james@and.org
Wed Jun 30 15:43:00 GMT 1999


"Martin v. Loewis" <martin@mira.isdn.cs.tu-berlin.de> writes:

> > I've been following this thread from the beginning, but I don't have the
> > ANSI/ISO standard for C, and I'd like to know more about what kind of code is
> > conformant and what isn't.
> 
> Tim already answered that, but then also explained what optimizations
> the compiler can do. Here's just the rule, in different wording:
> 
> <rule>
> Any access to an object of some type through a pointer of a different,
> incompatible type is invalid (unless the different type is char*).
> </rule>
> (Look Ma, I didn't say 'alias':)
> 
> <example>
> So if you have 
> 
>   struct foo *my_foo = get_some_foo();
>   struct bar *my_bar = (struct bar*)my_foo;
> 
> then writing
> 
>   my_bar->some_date = 42;
> 
> is incorrect (actually, undefined). However, writing

 Presumably unless..

 struct bar
 {
   struct foo; /* initial member */ 
   /* more stuff */
 }

 is the case ... and maybve even struct foo being an opaque type
defined in another translation unit which is compatible with struct
bar ? 

-- 
James Antill -- james@and.org
If you go to the Third World and find 100 people who have never tasted ketchup
before, you find out two things: one is that people don't actually like tomato
ketchup, the other is that they dislike all ketchups equally. -- Rob Young.



More information about the Gcc mailing list