flexible array member size

Geoff Keating geoffk@geoffk.org
Fri Dec 1 16:47:00 GMT 2000


Richard Henderson <rth@twiddle.net> writes:

> Well formed or no?  Currently we get
> 
> z.c:6: sizeof applied to an incomplete type
> 
> which seems the least correct option.
> 
> 
> r~
> 
> 
> struct s {
>    int x;
>    int y[];
> } s;
> 
> char test[sizeof (s.y) == 0 ? 1 : -1];

The ISO C standard says, s. 6.2.5, para 22, "An array type of unknown
size is an incomplete type."  You can't define variables of
incomplete types (s. 6.7 para 7), so the definition

struct s {
   int x;
   int y[];
} s;

is ill-formed and I think requires a diagnostic.  (It also doesn't
make sense.)

-- 
- Geoffrey Keating <geoffk@geoffk.org>


More information about the Gcc-bugs mailing list