mardi 22 novembre 2016

Checking if a variable has a given value with a macro if-statement in C++

This is a basic question, but I just can't find the exact answer for it. I have a variable x defined as such:

int x = 3;

Now, is there a way that I can use a macro #if statemend to check whether x equals 3?

I tried te obvious:

int x = 3;
#if x == 3
//do something
#endif

But this does not work, of course. The condition that is true for this macro is only that x == x. It does not recognize x == 3 as being true. Is there a way to implement that, or in other words, to have a macro-condition be related to a given variable?

If possible, without defining a new macro. If that's necessary, fine.

Aucun commentaire:

Enregistrer un commentaire