PDA

View Full Version : Conditional compilation



ro37bis
- 8th July 2011, 12:25
Hi guys,
I need some conditional compilation.
Normally I use the @ifdef, @ifndef ... @endif statements to enable or disable some code and it works.
But if I need to switch some Variabile declaration like:


@ ifdef Devboard
EnterKey VAR Key.0
StopKey VAR Key.1
StartKey VAR Key.2
@ else
EnterKey VAR Key.2
StopKey VAR Key.0
StartKey VAR Key.1
@ endif
I obtain the error message: variable already an alias
for each duplicate variable declaration line.

There is another way to obtain the conditional change of assignment?
Thk you
Roberto

Darrel Taylor
- 8th July 2011, 20:42
The @ ifdef statements only work during assembly, but that's AFTER the PBP program has been compiled.
So it can't directly affect PBP variables.

However, in ASM you can undefine bit variables and re-define them, which has pretty much the same effect.


Key VAR PORTB
EnterKey VAR BIT EXT :@ #undefine EnterKey
StopKey VAR BIT EXT :@ #undefine StopKey
StartKey VAR BIT EXT :@ #undefine StartKey
ASM
ifdef Devboard
#define EnterKey _Key,0
#define StopKey _Key,1
#define StartKey _Key,2
else
#define EnterKey _Key,2
#define StopKey _Key,0
#define StartKey _Key,1
endif
ENDASM

ro37bis
- 10th July 2011, 23:02
Thanks Darrel, as always, your help is effective and wellcome.
Roberto