MISRA Discussion Forums
Rule 19.16 - 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.19 Preprocessing Directives (https://forum.misra.org.uk/forumdisplay.php?fid=43)
+---- Thread: Rule 19.16 (/showthread.php?tid=205)



Rule 19.16 - nikunj - 02-02-2006

The syntax errors the rule talks about would any way be reflected as an sytax error by the compiler.

for example in
#defineNAME \"test\"

the complier would return an error.

So in effect the rule becomes redundant!


- lv - 02-02-2006

The compiler does not produce an error if the syntax error is inside a condition compilation branch which are not \"selected\".

Example:

Code:
#define AAA 2

int foo(void)
{
   int x;

#ifndef AAA
   x = 1;
  rlhegsfldghsfdghlsfd
#else
   x = 0;
#endif
   return(x);
}

This code will not produce an error, because AAA is define and so, the syntax error is inside the exclued code.

In the MISRA example:

Code:
#define AAA 2

int foo(void)
{
   int x;

#ifndef AAA
   x = 1;
#else1
   x = 0;
#endif
   return(x);
}

If AAA is defined then all code after the #ifndef is ignored until a #else, #elif or #endif instruction. In the example, there is a syntax error on #else and so, if AAA is define all code between #ifndef and #endif will be exclued and the result code will be, without any error:

Code:
#define AAA 2

int foo(void)
{
   int x;

   return(x);
}

But the desired behavior was certainly:
Code:
#define AAA 2

int foo(void)
{
   int x;
  
   x = 0;

   return(x);
}

So, this rule is not redundant.


- misra-c - 27-04-2006

We agree with LV's answer.