# #define

Hi !
I’m trying to create lines code to manage potential error with some “#define variable”.

In fact, I’ve 3 variables, taking either 0 or 1 as entry. If one of them is at 1, the 2 other have to be at 0.

Here is my code :

#define Variable1 1
#define Variable2 0
#define Variable3 0

#if Variable1 == 1
#define Variable2 0
#define Variable3 0
#endif

#if Variable1 == 0
#if Variable2 == 0
#define Variable3 1
#endif

#if Variable2 == 1
#define Variable3 0
#endif
#endif

The error (that I understand well !) is that I can’t define 1 variable twice.
So, what other solution would I have ?

Thank you for the help !
Lauranne

Hi Lauranne,

You can use #undef before you define them for the second time. But it kind of sets the priority for the Variable1, and then Variable2. But it can also probably be done somehow smarter too.
Something in the direction of:

#define a 1
#define b 0
#define c 0

#define Variable1 1*(1-(1-b)-(1-c))
#define Variable2 1*(1-(1-a)-(1-c))
#define Variable3 1*(1-(1-a)-(1-b))

Please note that i intentionally added 1*() as these blocks will be use to replace Variable# in the code below.

Regards,
Pavel

Hi Pavel !
Thank you for these solutions ! Works great !

Regards,
Lauranne