Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 19.16
#2
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.


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)