[previous] 0881 [next] Using multiple ## operators in the same macro definition.
Macro Definition REFERENCE - ISO:C90-6.8.3.3 The ## Operator - Semantics

More than one ## operator is present in this macro definition.

The order in which ## operators are evaluated during preprocessing is unspecified. In most situations this will be irrelevant, but it may be wise to avoid using more than one of them within the same macro because a macro which works with one compiler may fail with another.

In the following example, the expression "V(22)" may result in undefined behaviour if the left hand ## operator is not evaluated first because it is a requirement of ISO:C that the result of a ## operation should result in a "valid preprocessing token".

If the left hand ## is evaluated first, the result ("variable22") is a valid preprocessing identifier. If the right hand ## is evaluated first, the result ("22xx") is not a valid preprocessing token and the resulting behaviour will be undefined.

For example:


/*PRQA S 2017,3211,3408,3429 ++*/

#define V(n) variable##n##xx             /* Message 0881 */

int V(22) = 1;                           /* Possible undefined behaviour */


MISRA-C:2004 Rules applicable to message 0881:

Rule  19.12  (Required) There shall be at most one occurrence of the # or ## preprocessor operators in a single macro definition.


See also:

QA·C Source Code Analyser 8.1
MISRA-C:2004 Compliance Module 3.2
© 2012 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index Contents