[cfe-dev] Even more clang ideas

Mike Stump mrs at apple.com
Mon Aug 4 12:53:09 PDT 2008


On Aug 3, 2008, at 3:52 PM, John Engelhart wrote:
> Type punning was always frowned upon, and is now
> strictly forbidden in C99.  Except for 'union's, C doesn't really
> provide a means for multi-type pointer representations.  It's not
> really a question of what proper OO design paradigm is, it's a
> question of "where the rubber meets the road": How do you represent
> the concept in C.

We need not represent it in C.  We only need to be able to represent  
it in an AST for clang.  For gcc, we only need to be able to represent  
it in trees/gimple.

> To return anything other than a struct NSArray * breaks C99 type
> aliasing rules.  And because ObjC is so tightly integrated with C, and
> the fact that the bulk of the GCC compiler is geared towards C, one
> can not simply dismiss this as 'Well, that's how ObjC defines
> things.'

Actually, one can.  Please see the notion of alias sets in gcc for  
example.

> So, my question isn't really what the Objective-C 2.0 manual says
> (which is very little, and definitely not 'standards definition'
> quality), it's more about 'how do you do it?' (in the context of a
> modern, C99 optimizing compiler).

In gcc, easy, TYPE_ALIAS_SET (x) = 0;.



More information about the cfe-dev mailing list