Article View: comp.std.c
Article #2837Re: Pointers to Incomplete Types in Prototypes
From: Stephen Clamage
Date: Fri, 03 May 1991 16:01
Date: Fri, 03 May 1991 16:01
33 lines
1977 bytes
1977 bytes
lrg7030@uxa.cso.uiuc.edu (Loren J. Rittle) writes:
>In article <700@taumet.com> steve@taumet.com (Stephen Clamage) writes:
>>xor@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@taumet.com
Technical Details
Message-ID:
<702@taumet.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!lll-winken!uunet!taumet!steveReferences:
<w!2g7+c@rpi.edu> <700@taumet.com> <1991May2.164028.10641@ux1.cso.uiuc.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!lll-winken!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.std.c Subject: Re: Pointers to Incomplete Types in Prototypes Message-ID: <702@taumet.com> Date: 3 May 91 16:01:03 GMT References: <w!2g7+c@rpi.edu> <700@taumet.com> <1991May2.164028.10641@ux1.cso.uiuc.edu> Organization: Taumetric Corporation, San Diego Lines: 33