Outside of possible scenarios related to optimizing the entire program, code is generated for something like:
struct foo *bar; struct foo *test(struct foo *whatever, int blah) { return blah ? whatever: bar; }
completely independent of what members of struct foo can contain. Since make utilities usually recompile any compilation unit in which a full definition of the structure appears, even if such changes cannot actually affect the code they generate, it usually omits the full definitions of the structure from compilation units that do not really need them, and such an omission usually not worth the warning.
The compiler must have a complete structure or connection definition in order to know how to process objects of type declarations with automatic or static duration, aggregate declarations containing type elements, or code that refers to members of the structure or union. If the compiler does not have the information necessary to perform one of the above operations, it will have no choice but to curse it.
By the way, there is another situation where the Standard allows the compiler to require that the full definition of the join be visible, but does not require diagnostics: if two structures start with the Common Initial Sequence, and the type of join containing both is visible when the compiler processes code that uses a pointer to one of the structure types for checking a member of this Common Initial Sequence, the compiler must recognize that such code can access the corresponding structure element of another type. I donβt know which compilers, if any, adhere to the standard when the view of the continuous union is visible, but not when it is not [gcc is inclined to generate inappropriate code anyway if the -fno-strict-aliasing flag is used, in this case it will generate the appropriate code in both cases], but if you want to write code that uses the CIS rule in such a way as to guarantee the correct behavior on compatible compilers, you may need to make sure that the full definition of the connection type is visible; failure to do this may lead to the fact that the compiler will automatically generate dummy code.
supercat Feb 13 '17 at 16:30 2017-02-13 16:30
source share