Why rule 18.1?

6.18 Structures and Unions

Moderators: misra-c, david ward

Posts: 3
Joined: Mon Jul 23, 2007 3:53 pm
Location: Colorado, USA

Why rule 18.1?

Postby exoson » Thu Feb 19, 2009 11:11 pm

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?

Posts: 547
Joined: Thu Jan 05, 2006 1:11 pm

Re: Why rule 18.1?

Postby misra-c » Thu Mar 12, 2009 10:47 am

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).
Posted by and on behalf of
the MISRA C Working Group

Return to “6.18 Structures and Unions”

Who is online

Users browsing this forum: No registered users and 0 guests