02-02-2006, 11:35 AM
The compiler does not produce an error if the syntax error is inside a condition compilation branch which are not \"selected\".
Example:
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:
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:
But the desired behavior was certainly:
So, this rule is not redundant.
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.