Using the GNU C preprocessor, I want to declare a macro able to declare other macros for me, so that I can do:
and I get following macros declared:
NUMBER_ONE (which substitutes 1)
NUMBER_TWO (which substitutes 2)
NUMBER_THREE (which substitutes 3)
e.g., right like if I had done:
#define NUMBER_ONE 1
#define NUMBER_ONE 2
#define NUMBER_ONE 3
this is, the macro would get the number accordingly to the order in which it has been declared.
I know I can do:
But I don't know how can I get the order in which the macros have been declared instead of the "1", e.g. something that could retrieve the order in which they have been declared.
I have gone through http://gcc.gnu.org/onlinedocs/gcc-4.3.0/cpp/ but couldn't figure out a way using that.
Anyone has got any idea?
Thanks.
Code:
declare( ONE ); declare( TWO ); declare( THREE );
NUMBER_ONE (which substitutes 1)
NUMBER_TWO (which substitutes 2)
NUMBER_THREE (which substitutes 3)
e.g., right like if I had done:
#define NUMBER_ONE 1
#define NUMBER_ONE 2
#define NUMBER_ONE 3
this is, the macro would get the number accordingly to the order in which it has been declared.
I know I can do:
Code:
#define declare(NAME) { #define NUMBER_ ## NAME 1 }
I have gone through http://gcc.gnu.org/onlinedocs/gcc-4.3.0/cpp/ but couldn't figure out a way using that.
Anyone has got any idea?
Thanks.
Comment