Pointers to Incomplete Types in Prototypes
Loren J. Rittle
lrg7030 at uxa.cso.uiuc.edu
Thu May 2 05:07:08 AEST 1991
In article <w!2g7+c at rpi.edu> xor at aix01.aix.rpi.edu (Joseph Schwartz) writes:
>Must an ANSI C compiler accept pointers to incomplete types in a
>function prototype?
According to K&R's 2nd edition, in a word, yes. See page 212 (quoted here):
``Objects with an incomplete structure or union type may be mentioned
in contexts where their size is not needed, for example in declarations
(not definitions), for specifying a pointer, or for creating a typedef,
but not otherwise.''
>More specifically, if struct bar has not been defined, is an ANSI
>compiler allowed to reject the following prototype:
>
> extern void foo(struct bar *);
As the size of bar is not needed in the prototype for foo, the
above should be accepted by an ANSI compiler even if bar is
incomplete.
>According to 3.1.2.5, struct bar is an incomplete type in this case,
>and struct bar * is a pointer to an incomplete type.
>
>I couldn't find anything in 3.5.4.3 that allows or forbids incomplete
>types, or pointers to them, in function prototypes. Can anyone give
>me more conclusive information? 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.
As an aside, the SAS/C 5.1 (more or less) ANSI compiler accepts the
above line of code no problem. Good luck getting HP to upgrade their
compiler. May the big guns be with you.
>Joe Schwartz
Loren J. Rittle
l-rittle at uiuc.edu
--
``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