Rule 19.11 clarification request

6.19 Preprocessing Directives

Moderators: misra-c, david ward

Locked
rmgalles
Posts: 7
Joined: Fri Jan 20, 2006 3:45 pm
Location: USA

Rule 19.11 clarification request

Post by rmgalles » Wed Apr 18, 2007 1:50 pm

As stated and taken literally, this rule might be interpreted as requiring all identifiers used in any preprocessing directive be derived from a previous #define (is this the meaning of \"macro identifier\")?

Instead, I understand the rule as only requiring all identifiers used in the controlling constant-expression of #if and #elif preprocessing directives to be defined before use (unless the identifier is used as the operand of the defined() operator). However, identifiers used in the replacement-list of a #define preprocessing directive need NOT be \"defined before use\" as they may be ordinary identifiers and not defined by any #define preprocessing directive.

Otherwise, the identifier in a #define preprocessing directive itself could technically be interpreted as not meeting this rule, as the identifier isn't fully defined until after the directive has been processed. Thus, the only practical preprocessing directives covered by this rule appear to be #if and #elif directives.


As such, the rule might be more clearly stated as:
All identifiers used in the controlling constant expression of #if or #elif preprocessing directives shall be #defined before use, unless the identifier is an operand of the defined() operator.
Is my understanding and restating of the rule correct? Or, does this rule actually expect every identifier, including those in every #define \"macro body\" (replacement-list) to be defined before use (by a previous #define)?

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

Post by misra-c » Wed May 09, 2007 6:32 pm

Your restatement of the rule as follows is correct.
All identifiers used in the controlling constant expression of #if or #elif preprocessing directives shall be #defined before use, unless the identifier is an operand of the defined() operator.
We have used the term macro identifier to refer to macro names - see ISO 6.1.2
---
Posted by and on behalf of
the MISRA C Working Group

Locked

Return to “6.19 Preprocessing Directives”