Newsgroups: comp.std.c Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!m.cs.uiuc.edu!roundup.crhc.uiuc.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: <1991May2.164028.10641@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: <700@taumet.com> Date: Thu, 2 May 1991 16:40:28 GMT Lines: 55 In article <700@taumet.com> steve@taumet.com (Stephen Clamage) writes: >xor@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@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@uiuc.edu