On a software project (some old C compiler) we have a lot of variables which have to be saved normal and inverted.
Has somebody a idea how i can make a macro like that?
SET(SomeVariable, 137);
which will execute
SomeVariable = 137; SomeVariable_inverse = ~137;
Edit:
The best Solution seems to be:
#define SET(var,value) do { var = (value); var##_inverse = ~(value); } while(0)
Thanks for the answers
One hazard I haven’t seen mentioned is that the ‘value’ macro argument is evaluated twice in most of the solutions. That can cause problems if someone tries something like this:
After this call, myVariable would be 10 and myVariable_inverse would be ~11. Oops. A minor change to JaredPar’s solution solves this: