9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] const declarators in structs
@ 2000-11-16 10:35 Stephen Parker
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Parker @ 2000-11-16 10:35 UTC (permalink / raw)
  To: '9fans@cse.psu.edu'

i spent a while this morning pondering what an error message from 8c meant.
i tracked it down to a struct of the form:

struct S {
	int const *p;
};

the compiler suggested that unnamed objects in structs should be of struct
type.

(i know that const isn't really a plan9 thing, but this was a bit of code
from a small device that i was trying to port.)

stephen


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [9fans] const declarators in structs
@ 2000-11-16 21:23 Richard Miller
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Miller @ 2000-11-16 21:23 UTC (permalink / raw)
  To: 9fans

stephen.parker@pitechnology.com reports a misleading C compiler error message from:

struct S {
	int const *p;
};

The underlying cause is that the compiler expects const/volatile keywords before
other simple type names in a structure/union element declarator (but nowhere else) --
in the same context "const int *p" is considered acceptable.

Is this a deliberate choice or an oversight?  If the latter, a simple correction
is to change the grammar as follows:

/sys/src/cmd/cc/cc.y:216 c cc.y:216
< 	etlist
---
> 	tlist
/sys/src/cmd/cc/cc.y:221 c cc.y:221
< |	edecl etlist
---
> |	edecl tlist

The definitions of etlist, etypes and tnlist then become redundant and can be
pruned from cc.y as well.

-- Richard Miller



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2000-11-16 21:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-11-16 10:35 [9fans] const declarators in structs Stephen Parker
2000-11-16 21:23 Richard Miller

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).