2 questions for 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: 2 questions for rule 18.1 (/showthread.php?tid=692) |
2 questions for rule 18.1 - pmhill - 25-11-2009 The rule applies to structure definitions that are incomplete, but I see from exemplar suite file mc2_1801.c the following unexpected violation: struct { int8_t a; int8_t b [ ]; /* Not Compliant - constraint error 6.5.2.1 */ } mc2_1801_st = { 1, { 2, 3, 4 } }; Are you including as "incomplete" any structure that has a flexible array member? Apart from this, what other 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 or to compute sizeof, etc. So I cannot think of any legal C code that would be a violation of this rule. Re: 2 questions for rule 18.1 - jbezem - 26-11-2009 Flexible array members are a feature of C99 and therefore not allowed according to the MISRA Standard (the current version of MSRA, 2004, is explicitly restricted to C89/C95). From a C89 point of view, the type is incomplete, and therefore in violation of 18.1. If your compiler is silently (or by instruction) allowing certain/all C99 features to be used, your compiler will not consider the type itself incomplete, even if it is from the C89 viewpoint. HTH, Johan Re: 2 questions for rule 18.1 - misra-c - 20-01-2010 The example cited was added to the exemplar suite because at least one commercial C90 compiler was found to accept flexible array members even though they are not part of the C90 language standard. The exemplar suite for Rule 18.1 also includes an example of references to types that are incomplete which in turn lead to undefined behaviour. |