> 8c silently accept the above definition and sizeof(U) is 100.  ???
> The sources which include the definition of "NeverDefined" are
> regularly compiled too and sizeof(U) = 100 + sizeof(NeverDefined).
> 

i think the issue is that there isn't currently a distinction
between this

        typedef struct A A;
        struct A {
                int     expand[0];
        };

which is perfectly legal and this

        typedef struct U U;
        typedef struct A A;
        struct A {
                U;
        };

which might be allowed, but i can't find any references
that say it is.  the argument for having expandable
structures would be it would allow something like this

        typedef struct Priv Priv;
        typedef struct Pub Pub;
        struct Pub {
                ...
                Priv;
        };
        #pragma incomplete Pub

        Pub     *pubfn(void);

but i don't see any such uses in /sys/include.
this change will generate a diagnostic for your code,
but be careful.  this is a corner of c, and what seems
intuitively correct in the corners can often be wrong.

- erik

; diff -c dcl.c `{yesterday -n2 dcl.c}
dcl.c:541,547 - /n/dump/2009/0710/sys/src/cmd/cc/dcl.c:541,547
                                l->offset = o;
                        } else {
                                if(l->width <= 0)
-                               if(l->down != T || l->width < 0)
+                               if(l->down != T)
                                        if(l->sym)
                                                diag(Z, "incomplete structure 
element: %s",
                                                        l->sym->name);

Reply via email to