17-04-2008, 04:19 PM
The rule states that C macros shall only expand to ...
This implies that the rule should only be invoked when the macro is expanded.
So for the not compliant example
A checking tool should not attempt to check the violation until the macro is used.
In fact when CAT is being processed for expansion, it requires PI to be expanded. PI expands to 3.14159F, which is a constant, so its expansion is o.k. The expansion of CAT looks for other preprocessing tokens after PI has been substituted. There are no more tokens, so CAT expands to 3.14159F and is therefore not in violation of rule 19.4.
If the example had been written as
Then the expansion of CAT would be to a non-parenthesised expression and rule 19.4 violated.
This implies that the rule should only be invoked when the macro is expanded.
So for the not compliant example
Code:
#define CAT PI /* non-parenthesised expression */
In fact when CAT is being processed for expansion, it requires PI to be expanded. PI expands to 3.14159F, which is a constant, so its expansion is o.k. The expansion of CAT looks for other preprocessing tokens after PI has been substituted. There are no more tokens, so CAT expands to 3.14159F and is therefore not in violation of rule 19.4.
If the example had been written as
Code:
#define CAT PI + PI
<t>Graham Andrews<br/>
Edinburgh Design Centre<br/>
Analog Devices Inc</t>
Edinburgh Design Centre<br/>
Analog Devices Inc</t>