Tuesday, May 22, 2012

C macro: how do I concatenate a name and a number which is result of a math operation (done also by preprocessor)?

Consider the following code:



1. #define SUFFIX 5-5
2. #define XFUNC_0( x ) (100 * x)
3. #define XFUNC_1( x ) (101 * x)
4. #define XFUNC_2( x ) (102 * x)
5. #define CATX( x, y ) x##y
6. #define CAT( x, y ) CATX( x, y )
7. #define XFUNC CAT( XFUNC_, SUFFIX )
8. #if XFUNC(2) == 200
...... etc
N.

No comments:

Post a Comment