03-04-2008, 06:41 AM
ISO C states that
\"An identifier currently defined as an object-like macro shall not be redefined by another #define preprocessing directive unless the second definition is an object-like macro definition and the two replacement lists are identical. Likewise, an identifier currently defined as a function-like macro shall not be redefined by another #define preprocessing directive unless the second definition is a function-like macro definition that has the same number and spelling of parameters, and the two replacement lists are identical.\"
So your example is indeed legal ISO C, while this is not:
#define BILL some text
#define BILL some other text
Only if they are identical are they allowed by ISO C. And if they are identical, they are also harmless, so I see no point in a MISRA rule forbidding that.
\"An identifier currently defined as an object-like macro shall not be redefined by another #define preprocessing directive unless the second definition is an object-like macro definition and the two replacement lists are identical. Likewise, an identifier currently defined as a function-like macro shall not be redefined by another #define preprocessing directive unless the second definition is a function-like macro definition that has the same number and spelling of parameters, and the two replacement lists are identical.\"
So your example is indeed legal ISO C, while this is not:
#define BILL some text
#define BILL some other text
Only if they are identical are they allowed by ISO C. And if they are identical, they are also harmless, so I see no point in a MISRA rule forbidding that.