MISRA Discussion Forums
Why rule 18.1? - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA-C: 2004 rules (https://forum.misra.org.uk/forumdisplay.php?fid=17)
+---- Forum: 6.18 Structures and Unions (https://forum.misra.org.uk/forumdisplay.php?fid=48)
+---- Thread: Why rule 18.1? (/showthread.php?tid=629)



Why rule 18.1? - exoson - 19-02-2009

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?


Re: Why rule 18.1? - misra-c - 12-03-2009

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).