Pointers to Incomplete Types in Prototypes

Norman Diamond diamond at jit533.swstokyo.dec.com
Fri May 10 11:10:38 AEST 1991


In article <7330008 at hpfcso.FC.HP.COM> mev at hpfcso.FC.HP.COM (Mike Vermeulen) writes:
>>    extern void foo(struct bar *);
>> 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.
>
>Agreed.  I don't think there is anything in the standard that forbids such
>an incomplete type in a parameter list.
>The HP ANSI C compiler issues the following warning:
>	warning: struct 'bar' declared in parameter list will have scope
>		 limited to this function declaration or definition.

The problem, as someone else pointed out, is that struct 'bar'
IS NOT DECLARED in the parameter list.  It is REFERENCED in the
parameter list.

If the declaration were
   extern void foo(struct bar { /* fields */ } *);
then the HP ANSI C compiler's warning would be correct.

>The reason for the warning is to help in the diagnosis of a situation such as:
>	/* header file contents */
>	extern void foo(struct bar *);
>	struct bar { /* fields */ };
>	/* user code */
>	#include HEADER
>	struct bar *barp;
>	main(){
>		foo(barp);
>	}
>In this program, the compiler will diagnose a mismatch in parameter types at
>the call to foo().  The reason is that the first "struct bar" in the parameter
>list goes out of scope at the end of the declaration; so the next declaration
>of "struct bar" in the header file declares a new (incompatible) structure
>type.

Sorry, no.  There is only one declaration of a type "struct bar" in that
code, and it is referenced several times.  There is no compatibility problem.
--
Norman Diamond       diamond at tkov50.enet.dec.com
If this were the company's opinion, I wouldn't be allowed to post it.
Permission is granted to feel this signature, but not to look at it.



More information about the Comp.std.c mailing list