9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: erik quanstrom <quanstro@quanstro.net>
To: 9fans@9fans.net
Subject: Re: [9fans] C compiler question
Date: Sun, 12 Jul 2009 12:59:19 -0400	[thread overview]
Message-ID: <37a4205e0ebcee3f0fd82131999a1e5d@quanstro.net> (raw)
In-Reply-To: <4A595F8D.1080408@tecmav.com>

> 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	other threads:[~2009-07-12 16:59 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-12  3:59 Adriano Verardo
2009-07-12 16:59 ` erik quanstrom [this message]
2009-07-14  2:58   ` Adriano Verardo
2009-07-14  3:14     ` erik quanstrom
2009-07-14 14:00       ` Adriano Verardo
2009-07-14 14:57         ` erik quanstrom
2009-07-14 16:26           ` Adriano Verardo
2009-07-14 16:38             ` erik quanstrom
2009-07-14 17:18       ` Roman V Shaposhnik
2009-07-14 17:46         ` erik quanstrom
2009-07-14 18:59           ` Roman V Shaposhnik
2009-07-14 19:29             ` erik quanstrom
2009-07-14 19:45               ` Russ Cox
2009-07-15 11:34                 ` Ethan Grammatikidis
2009-07-15 11:38                   ` erik quanstrom
2009-07-14 20:28               ` [9fans] pointers to incomplete types Roman V Shaposhnik
2009-07-15  9:25               ` [9fans] C compiler question robert wilson
2009-07-14  4:00     ` Russ Cox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=37a4205e0ebcee3f0fd82131999a1e5d@quanstro.net \
    --to=quanstro@quanstro.net \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).