I want to do real addition (not just a replacement) of two macros and want to use their result in another macro.
for example.
#define NUM_1 1
#define NUM_2 2
#define NUM_3 3
#define ADD(X,Y) ((X)+(Y))
#define CAT_(X,Y) X##Y //For two layer of indirection
#define MY(NUMBER) CAT_(NUM_,NUMBER)
now this I want to use some thing like this
MY( ADD(NUM_1 , NUM_2 ))
or by this way
#define RESULT ((NUM_1) + (NUM_2))
MY( RESULT )
I'm expecting output as of MY(RESULT)
or MY(ADD(NUM_1,NUM_2))
as
NUM_3
Is it possible to do in the preprocessing stage? If yes please guide me how I can do.
I'm getting result NUM_((1)+(2))
which is completely fine according to preprocessor output.
I have framed my problem in simple addition form. Actually, My requirement is to use a result of one complex equation which will make relation to some 1000 macros in form of like EEPROM_PAGE_10
here 10
is an output of some other equation came by an arithmetic operation on another #define
macro and this I can't forward to the compiler.
Note This question is not same as Can I add numbers with the C/C++ preprocessor? because in that post we are replacing with the well-known result, for example, they have defined the macro like
#define ADD_1_AND_2 3
my requirement is different, I want to know that, Is it possible to convert ((2)+(1))
equal to 3
in preprocessing stage. so I can use 3
as NUM_3
for generating relevant output.