Rule 19.16

6.19 Preprocessing Directives

Moderators: misra-c, david ward

Locked
nikunj
Posts: 4
Joined: Wed Feb 01, 2006 11:08 am
Location: Bangalore, INDIA

Rule 19.16

Post by nikunj » Thu Feb 02, 2006 9:04 am

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
Posts: 9
Joined: Mon Oct 31, 2005 12:47 pm

Post by lv » Thu Feb 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:

Code: Select all

#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: Select all

#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: Select all

#define AAA 2

int foo(void)
{
   int x;

   return(x);
}
But the desired behavior was certainly:

Code: Select all

#define AAA 2

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

   return(x);
}
So, this rule is not redundant.

misra-c
Posts: 572
Joined: Thu Jan 05, 2006 1:11 pm

Post by misra-c » Thu Apr 27, 2006 12:07 pm

We agree with LV's answer.
---
Posted by and on behalf of
the MISRA C Working Group

Locked

Return to “6.19 Preprocessing Directives”