MISRA Discussion Forums

Full Version: Why rule 18.1?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Please help me understand the reason for rule 18.1. In the context of an "opaque pointer", one can properly make and use such a pointer to an incompletely typed structure. Having the full structure declaration is not needed. The committee has endorsed this in a previous post.

What coding practice is left that might cause a problem? If the type is incomplete, a compile error will result from any attempt to create an object of that type or refer to its members.

OK, but even so, why not require it? In header files, I like to code:
struct something; /* with a forward declaration, I can create pointers. */

void foo (struct something *pointerToSomething);

The prototype is valid even though "something" is of incomplete type. If the #including .c file does not need anything other than the pointer, why require #including yet another header merely to get the (unused) full declaration and satisfy the rule?
MISRA acknowledges that opaque types should be allowed and has changed Rule 18.1 to permit their use. Full details of this change are given in "MISRA-C:2004 Technical Corrigendum 1", which can be downloaded from the Resources / MISRA C resources area of the forum (registered users only).