Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why does the declaration extern int f(struct x *p); give me an obscure warning message about “struct x declared inside parameter list\?

0
Posted

Why does the declaration extern int f(struct x *p); give me an obscure warning message about “struct x declared inside parameter list\?

0

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. (The problem is that the structure and the tag go out of scope at the end of the prototype; see question 1.29.) To resolve the problem, you should probably rearrange things so that the actual declaration of the structure precedes the function prototype(s) using it. (Usually, both the prototype and the structure declaration will end up in the same header file, so that the one can reference the other.) If you must mention a hitherto-unseen structure in a prototype, 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: ISO Sec. 6.1.2.1, Sec. 6.1.2.6, Sec. 6.5.2.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123