From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <37a4205e0ebcee3f0fd82131999a1e5d@quanstro.net> From: erik quanstrom Date: Sun, 12 Jul 2009 12:59:19 -0400 To: 9fans@9fans.net In-Reply-To: <4A595F8D.1080408@tecmav.com> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Subject: Re: [9fans] C compiler question Topicbox-Message-UUID: 1c68fff2-ead5-11e9-9d60-3106f5b1d025 > 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);