Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!samsung!uunet!stanford.edu!unix!clipper!baxter From: baxter@clipper.ingr.com (Bill Baxter) Newsgroups: comp.std.c Subject: Re: Pointers to Incomplete Types in Prototypes Summary: It is legal ANSI C. . Message-ID: <1991May2.201352.26471@clipper.ingr.com> Date: 2 May 91 20:13:52 GMT References: Organization: Intergraph Advanced Processor Division - Palo Alto, CA Lines: 65 In article , xor@aix01.aix.rpi.edu (Joseph Schwartz) writes: |> Must an ANSI C compiler accept pointers to incomplete types in a |> function prototype? |> |> More specifically, if struct bar has not been defined, is an ANSI |> compiler allowed to reject the following prototype: |> |> extern void foo(struct bar *); No, the compiler should not reject it on the grounds that it is an incomplete type. First, 'bar' may have been defined previously with file scope, hence this is an instance of that type. Second, incomplete pointer types are perfectly legitimate if all you are interested in is the pointer itself (i.e., you will not attempt to dereference what it points to without casting to a known type). Our compiler allows this construct. Good luck with HP! A more twisted case, and probably totally useless, is when you have the following compilation module: -----start f.c------- int foo (struct s s) { struct s { int i; }; return s.i; } -----end f.c--------- Since the identifiers in the prototype definition have function scope, should this be legal ANSI C? I can find no convincing verbiage in the standard that would rule-out this case. Our compiler currently does not accept this, but I fear it should and we are currently seeking convincing arguments for why we shouldn't have to implement it. |> |> 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. I think you have a legitimate gripe. At the prototype declaration site, you may have no need for the complete structure type. Consider a module that is manipulating pointers only, without regards to what is being pointed to. Therefore, it would be sufficient to have an incomplete type. You might be pulling pointers out of a data structure passing them to this function that might understand what is being pointed to. |> |> Thanks in advance for any help you can provide. |> |> |> -- |> Joe Schwartz |> Internet: xor@mts.rpi.edu |> Bitnet: userez3n@rpitsmts -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Bill Baxter Compiler Group: Advanced Processor Division (415)852-2333 E-MAIL: {apple|pyramid}!clipper!baxter USPS: 2400 Geng Rd., Palo Alto, CA 94303 _STD_DISC: INGR has their opinions. I have mine. Believe them if conflicting.