Compiler directive #if

I have a device that can log into either one of two accounts.
The log-in credentials for both accounts are embedded in the code as #define statements.
When building the firmware for upload, I want to specify in one spot a condition that tell the compiler which set of #defines to compile and ignore the other set. The condition switch is the constant integer Account and it's set to 1.
The code below fails. It chooses the 2nd account when I want it to choose the first account.
why?

const int Account = 1; //set Account = 1 to build a firmware upload for Account 1
#if Account == 1
//use 1st account credentials
#undef AUTH
#define AUTH "xxxxxxxREDACTED1xxxxxxx"
#define Acct 1

#else // use 2nd account credentials
#undef AUTH
#define AUTH   "xxxxxxREDACTED2xxxxxxx"
#define Acct 2
#endif

Did you mean

#define Account 1

?

Inspect the include files for the use of
#ifdef

I use it as follows:
#define DBG
#ifdef DBG
Serial.begin(9600);
#endif
.
.
.
#ifdef DBG
Serial.println("some diagnostic");
#endif

It's clumsy, but most of the time, I'm just tracking code progress, so it works. There are much more sophisticated examples here, somewhere.

Well maybe, if that's what it takes. I'll try it.

I was trying to follow this rule:

The condition that follows #if or #elif can only evaluate constant expressions, including macro expressions.

so I though the expression must be a simple integer expression.

Thank-you. I've been struggling with this for a while.

#define = Account 1 

It worked.

As @anon56112670 pointed out, this is wrong. It makes Account an integer variable, inaccessible by the pre-compiler. You must define Account as a pre-compiler macro symbol.

conventional

#undef AUTH
#ifdef AUTH
# define AUTH "xxxxxxxREDACTED1xxxxxxx"
#else
# define AUTH "xxxxxxREDACTED2xxxxxxx"
#endif

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.