[comp.lang.c] Question on external struct declarations in ANSI C

arnold@emory.uucp (Arnold D. Robbins {EUCC}) (08/03/87)

I recently put up the latest version of GNU CC (1.7) on my vaxen. Noticing
that it produced really nice code, I decided that, *for fun*, I would try
recompiling my kernel with it. (Let's NOT restart the whole "optimize my
kernel" discussion; that's not what I am interested in.)

Well, the kernel header files are full of declarations like

	extern struct pte Mbmap[];		/* page tables to map mbutl */

where, e.g., what a 'struct pte' is has not been previously defined. /bin/cc
lets you do this, and does not complain until you try to actually use one of
these things or a member of one. GNU CC, on the other hand, promptly dies
miserably when it sees such a declaration. GNU CC claims to follow the rules
of (a version of) the draft standard.

My question is, "is such a declaration illegal?". If so, could someone cite
chapter and verse in the current ANSI draft standard? If such a declaration,
*without* any subsequent use, is illegal, then an awful lot of existing
code is going to break.

On the other hand, if GNU CC is broken, then the GNU people need to be
told about it.

Thanks,
-- 
Arnold Robbins
ARPA, CSNET:	arnold@emory.ARPA	BITNET: arnold@emory
UUCP:	{ decvax, gatech, sun!sunatl }!emory!arnold
ONE-OF-THESE-DAYS:	arnold@emory.mathcs.emory.edu

drw@cullvax.UUCP (Dale Worley) (08/04/87)

arnold@emory.uucp (Arnold D. Robbins {EUCC}) writes:
> Well, the kernel header files are full of declarations like
> 
> 	extern struct pte Mbmap[];		/* page tables to map mbutl */
> 
> where, e.g., what a 'struct pte' is has not been previously defined. /bin/cc
> lets you do this, and does not complain until you try to actually use one of
> these things or a member of one. GNU CC, on the other hand, promptly dies
> miserably when it sees such a declaration. GNU CC claims to follow the rules
> of (a version of) the draft standard.

Well, reading 3.5.2.2 and 3.5.3.2 of the draft suggests that this
module doesn't need to know the size of Mbmap at all (unless you
sizeof it or something), and so the size of struct pte doesn't need to
be known, and so struct pte need not be fully declared.

Dale

-- 
Dale Worley	Cullinet Software		ARPA: cullvax!drw@eddie.mit.edu
UUCP: ...!seismo!harvard!mit-eddie!cullvax!drw
OS/2: Yesterday's software tomorrow

rbutterworth@orchid.UUCP (08/05/87)

In article <1429@cullvax.UUCP>, drw@cullvax.UUCP (Dale Worley) writes:
> arnold@emory.uucp (Arnold D. Robbins {EUCC}) writes:
> > 	extern struct pte Mbmap[];		/* page tables to map mbutl */
> Well, reading 3.5.2.2 and 3.5.3.2 of the draft suggests that this
> module doesn't need to know the size of Mbmap at all (unless you
> sizeof it or something), and so the size of struct pte doesn't need to
> be known, and so struct pte need not be fully declared.

Which of course implies that either
1) all structs must be aligned on a long double boundary, or
2) all sizeof(struct X*) pointers must be as big as (char *) pointers.

On some machines (e.g. sizeof(char*) = 2*sizeof(int*),
and alignof(long double) = 16), either choice can be fairly
wasteful in terms of both space and cpu, all in the name of
compatibility with old programs written by people too lazy
to declare types when they could get away with it.