PDA

View Full Version : Conditional compile



pedja089
- 16th January 2014, 21:10
Hi,
I'm trying to create include file. I need way to create conditional compile based on whether variable is defined or not in main file.
Something like this:

#IFNDEF TmpB
TmpB VAR BYTE
#ENDIF
If variable is all ready defined, it won't compile just show error:Bad defined value
If variable isn't defined then I got syntax error.

#IFDEF Counter2
Counter2=Counter2+1
#ENDIF
For this, if variable isn't define, it's ok, but if is defined then I get Bad defined value.

Is there way to do that?

HenrikOlsson
- 16th January 2014, 21:38
Hi,
I might be wrong but I don't think you can do that.
The #IFNDEF Tmp2 will check if you've previoulsy not done #DEFINE Tmp2, where Tmp2 in this case a compile-time constant Tmp2 (not a PBP constant OR PBP variable).

So, the only way to do it is to also define "something" in the main file, at the same time as you declare your Tmp2 variable and then check that "something" - not ideal but I think (though I'd like to be wrong) it's the only way.

Tmp2 VAR BYTE
#DEFINE VarCreated



#IFNDEF VarCreated
Tmp2 VAR BYTE
#ENDIF

Again, I hope I'm wrong because I can see what you're trying to do could be useful.

/Henrik.

pedja089
- 16th January 2014, 22:25
Thanks.
I know that I could use define for each var, but then I need lot of them and probably it would be messy. Especially if I forget to put one or two define :)
That is last option...
If conditional compile depend on variables, there is almost no way to overlook some of option's.