Pointers to Incomplete Types in Prototypes

Stephen Clamage steve at taumet.com
Sat May 4 02:01:03 AEST 1991


lrg7030 at uxa.cso.uiuc.edu (Loren J. Rittle) writes:

>In article <700 at taumet.com> steve at taumet.com (Stephen Clamage) writes:
>>xor at aix01.aix.rpi.edu (Joseph Schwartz) writes:
>>>    extern void foo(struct bar *);
>>
>>As shown, the prototype declares "struct bar" to be an incomplete type
>>*local to the prototype*, and hence unavailable outside the prototype.
>>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 */

>It does not matter.  According to my understanding of the standard and
>according to my ANSI C compiler the following is valid code:

>struct bar *getbar(int);
>void changebar(struct bar *, int);

The two cases are not the same.  The example you give is valid, because
the first 'struct bar' does not appear inside the parameter list
in the first prototype; it has file scope (assuming this declaration
is at the file level).  Section 3.2.1.1 of the Standard defines scopes
of identifiers.  It says in part

   "If the declarator or type specifier that declares the identifier
    appears within the list of parameter declarations in a function
    prototype (not part of a function definition), the identifier has
    *function prototype scope*, which terminates at the end of the
    function declarator." [italics in the Standard]
-- 

Steve Clamage, TauMetric Corp, steve at taumet.com



More information about the Comp.std.c mailing list