Path: utzoo!utgpu!cunews!cognos!jimp From: jimp@cognos.UUCP (Jim Patterson) Newsgroups: comp.std.c Subject: Re: Pointers to Incomplete Types in Prototypes Message-ID: <9600@cognos.UUCP> Date: 2 May 91 20:37:48 GMT References: <700@taumet.com> Reply-To: jimp@cognos.UUCP (Jim Patterson) Organization: Cognos Inc., Ottawa, Canada Lines: 58 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. That in itself should not be considered a reason to issue an error. We have this situation a lot, because we use prototype headers in all of our files and in quite a few instances there are missing struct declarators for functions we don't call in that module. If you do try to call a function with an incomplete struct type, then you get a pointer mismatch error which is unavoidable if you don't first declare the struct type no matter how you try to cast it. Actually, I'm a bit confused by this whole thing, because we also have a HP system (HP 9000/835 running HP/UX 7.0), and the problem doesn't occur with our compiler. When I compiled extern void foo(struct bar *); it compiled fine. We have had a similar problem, but only where there is a typedef involved, e.g.: extern void foo(bar *); where 'bar' is intended to be a typedef, e.g. what's missing is typedef struct Bar bar; Here, you quite legitimately get an error because it doesn't know what 'bar' is (it assumes its a parameter name, and gives an "unexpected symbol" error at "*"). This is however not the same problem that was reported by Joseph Schwarz. You also get an error if you declare foo twice because the two definitions aren't compatible (struct bar in the first declaration is not the same as struct bar in the second, unless again you declare struct bar before the first occurrence of foo's prototype). The error given is 'Inconsistent parameter list declaration for "foo"'. I think this is also a legitimate error, though a confusing one. -- Jim Patterson Cognos Incorporated UUCP:uunet!mitel!cunews!cognos!jimp P.O. BOX 9707 PHONE:(613)738-1440 x6112 3755 Riverside Drive Ottawa, Ont K1G 3Z4