I am working on a backward compatibility project and so, I need to re-define things without messing with old code. I want to use the output as one of the params in a #define.
For example : my old code contains
#define OPERATION(y) ...
and we used it
x = OPERATION(y);
in the new code we have:
#define OPERATION_NEW(y,x) ...
and we use it like:
x = OPERATION_NEW(y,x);
notice that now x is a result and a param.
I want to be able to do the next:
#define OPERATION(y) OPERATION_NEW(y,__output__)
(I want to be able to get the output as a param and use it in the define…)
is it possible ? and if so, how ? if not , is there a solution for this situation ? I have tones of old code that have the OPERATION(y) and want to re-direct it to OPERATION_NEW(y,x) -while keeping in mind that x must be the output…
Not really. There’s no such thing as an “output” for a macro. In this particular case,
OPERATION(y)is a macro which expands to an expression. That expression is subsequently assigned tox.But the preprocessor handles just the macro, not the assignment. It doesn’t know or care about the previous token. The compiler only sees the assignment and the expressions on both sides, not the macro. Neither has a complete picture.