Pointers to Incomplete Types in Prototypes
Loren J. Rittle
lrg7030 at uxa.cso.uiuc.edu
Fri May 3 02:40:28 AEST 1991
In article <700 at taumet.com> steve at taumet.com (Stephen Clamage) writes:
>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.
What are you talking about? This is not true, see below.
>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.
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);
void main(void)
{
struct bar *mybar;
mybar = getbar (1);
if (mybar)
changebar (mybar, 2);
}
This is very nice and allows data hiding, etc. Steve, if you are right
then I better get on the phone to my C compiler vendor. Can one of the
standard writers, please enlighten us?
>Steve Clamage, TauMetric Corp, steve at taumet.com
Loren J. Rittle
--
``NewTek stated that the Toaster *would* *not* be made to directly support
the Mac, at this point Sculley stormed out of the booth...'' --- A scene at
the recent MacExpo. Gee, you wouldn't think that an Apple Exec would be so
worried about one little Amiga device... Loren J. Rittle l-rittle at uiuc.edu
More information about the Comp.std.c
mailing list