Pointers to Incomplete Types in Prototypes

Stephen Clamage steve at taumet.com
Fri May 3 01:24:07 AEST 1991


xor at aix01.aix.rpi.edu (Joseph Schwartz) writes:

>More specifically, if struct bar has not been defined, is an ANSI
>compiler allowed to reject the following prototype:
> 
>    extern void foo(struct bar *);

>Our HP "ANSI" C compiler is complaining
>about the above prototype, and I want some ammunition before I report
>it to HP as a problem.

There was another answer posted to this question which was not complete.
As shown, the prototype declares "struct bar" to be an incomplete type
*local to the prototype*, and hence unavailable outside the prototype.
It is then impossible to call this function, since no object of type
"struct bar" (or pointer to one) could ever exist.  (Any later "struct
bar" is a new type in a different scope.)  The compiler may have been
complaining about this.

If you precede the declaration with an incomplete decl for bar, the
prototype now refers to that decl, and all is well.  Example:
	struct bar;			/* defined later */
	extern void foo(struct bar*);	/* refers to previous bar */

You didn't say whether there was a prior incomplete decl.
-- 

Steve Clamage, TauMetric Corp, steve at taumet.com



More information about the Comp.std.c mailing list