MISRA Discussion Forums

Full Version: Rule 19.16
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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!
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.
We agree with LV's answer.