[cfe-commits] r64239 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.def lib/Sema/SemaType.cpp test/Sema/array-constraint.c test/Sema/flexible-array-init.c

Mike Stump mrs at apple.com
Tue Feb 10 17:25:50 PST 2009


On Feb 10, 2009, at 2:47 PM, Daniel Dunbar wrote:
> Agh! Do we really need to accept this!?
>
> What does f0 compute:
> --
> struct S0 {
>  int a;
>  int b[];
> };

Note, it _must_ be at the end of the struct.  And the semantics are it  
is of 0 size.  This is useful for malloc (sizeof (base) + n *sizeof  
(elt)) style allocations.  They allow nesting, not because all  
compositions work, but because some do, for example:

struct SB {
   int i;
};

struct SD {
   int a;
   int b[];
};

struct S1 {
   struct SB x;
   struct SD y;
};

Hard errors in the cases that don't make sense I think should be fine;  
any existing code, I bet doesn't make that sort of use, and we can  
file a bug report against gcc to slightly tighten up the cases we know  
are insane.

They use array, and array always works, just so long as you only ever  
have 1 element.  I suspect they do this, because C doesn't have  
references.  :-)



More information about the cfe-commits mailing list