Problem with prototypes and incomplete types

Doug Gwyn gwyn at smoke.BRL.MIL
Tue Feb 28 03:47:31 AEST 1989


In article <237 at harrier.ukc.ac.uk> mtr at ukc.ac.uk (M.T.Russell) writes:
>Is gcc right to object to incomplete types in function prototypes?

Logically it might be thought to make a difference.  However, we
once deduced from various constraints scattered throughtout the C
language that "all structure pointers have to smell the same", i.e.
have the same representation.  (Strictly speaking, this assumes the
compiler is not applying global code analysis to identify places
where shortcuts can be applied, so there should be an "as if" in
there somewhere.)  Therefore, the compiler should easily be able to
cope with not knowing the precise structure type in your example.
An incomplete array is similarly no problem.  An incomplete struct
or union parameter (as opposed to a pointer to one) could be more
bothersome, but not noticeably worse than for incomplete data types.

I don't think the pANS disallows an incomplete type in this context.
Certainly the problem is not that the struct tag "object" had
prototype scope, because the scope of the tag had already begun.

>One workaround is to declare destroy as
>	void (*destroy)(void *);

Better in this particular example might be
	void (*destroy)();
so that SOME type checking could still be performed.

I don't recall any public review comments on this, but it's a good
point.  I hope I've interpreted this correctly..



More information about the Comp.std.c mailing list