struct declarations in dpANS C

Karl Heuer karl at haddock.ima.isc.com
Sat Oct 22 05:34:02 AEST 1988


In article <6157 at june.cs.washington.edu> uw-june!pardo (David Keppel) writes:
>I have code of the form:
>    typedef void (*rtl_fp)( struct save_t *, int n,  rtl_t *curr );

Identifiers declared within a prototype have very short scope; thus for
example `n' has a scope that extends only to the end of the prototype.
Similarly (and more subtly), `struct save_t' has this same short scope if it
hasn't been previously declared.  When you later declare `struct save_t' it
has a nonintersecting scope, and therefore is considered a different type.

>[the error occurs] unless I precede the function declaration with
>    struct save_t;

That's the correct way to do it; if the struct tag is already declared when
the prototype is encountered, the one in the prototype becomes a reference to
it instead of a new type.

>In which case the compiler notes that there is an "empty declaration".

That is incorrect.  The struct tag is being declared.

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.std.c mailing list