Newsgroups: comp.std.c Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!xor From: xor@aix01.aix.rpi.edu (Joseph Schwartz) Subject: Re: Pointers to Incomplete Types in Prototypes Message-ID: Nntp-Posting-Host: aix01srv.aix.rpi.edu Organization: Rensselaer Polytechnic Institute, Troy NY References: <700@taumet.com> Date: 3 May 91 05:45:20 GMT Lines: 43 In article <700@taumet.com> steve@taumet.com (Stephen Clamage) writes: > >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. > >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. No, there was no prior incomplete declaration of struct bar. Your claim that struct bar has local scope to the prototype is pretty scary. In many of our cases, a function foo is declared with a prototype in an included header file, and then a struct bar is defined in a second included header file, and finally the function foo is called from the .c file that's been doing the #including. Now, if I understand you correctly, I should never be allowed to call function foo, because the struct bar * that I pass to it is incompatible with the struct bar * that it was declared to take as a parameter. Can you please direct me to the section of the Standard that supports this? Specifically, I want to know where it says that struct bar has scope local only to the prototype. I'm aware that if I said: extern void foo(struct bar *stool); then stool would be local to the prototype. I'm skeptical that this also holds for struct/union tags. -- Joe Schwartz Internet: xor@mts.rpi.edu Bitnet: userez3n@rpitsmts