Newsgroups: comp.std.c
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!caen!news.cs.indiana.edu!ux1.cso.uiuc.edu!uxa.cso.uiuc.edu!lrg7030
From: lrg7030@uxa.cso.uiuc.edu (Loren J. Rittle)
Subject: Re: Pointers to Incomplete Types in Prototypes
Message-ID: <1991May1.190708.21708@ux1.cso.uiuc.edu>
Sender: usenet@ux1.cso.uiuc.edu (News)
Reply-To: l-rittle@uiuc.edu (Loren J. Rittle)
Organization: University of Illinois at Urbana
References: <w!2g7+c@rpi.edu>
Date: Wed, 1 May 1991 19:07:08 GMT
Lines: 42

In article <w!2g7+c@rpi.edu> xor@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@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@uiuc.edu
