### Question 11.5

Why does the declaration

    extern f(struct x *p);

give me an obscure warning message about ``struct x introduced in prototype scope''?

In a quirk of C's normal block scoping rules, a structure declared (or even mentioned) for the first time within a prototype cannot be compatible with other structures declared in the same source file (it goes out of scope at the end of the prototype).

To resolve the problem, precede the prototype with the vacuous-looking declaration

    	struct x;

which places an (incomplete) declaration of `struct x` at file scope, so that all following declarations involving `struct x` can at least be sure they're referring to the same `struct x`.

References: ANSI Sec. 3.1.2.1, Sec. 3.1.2.6, Sec. 3.5.2.3
ISO Sec. 6.1.2.1, Sec. 6.1.2.6, Sec. 6.5.2.3

Read sequentially: prev next up top

This page by Steve Summit // Copyright 1995 // mail feedback