#IfDef inconsistency

tmfkam

Senior Member
#1
Just making a note to remind myself, and to warn others as much as anything.

There seems to be a difference in the way that '#IfDef' statements are parsed between the Windows PicAxe compiler, and the Mac version.

The following statements compile in Windows as expected:

Code:
#Define Show_Debug


#IfDef Show_Debug Then
    #Terminal 4800
#EndIf

Pause 100

#IfDef Show_Debug Then
    SerTxd("08M2 DFPlayer controller", CR, LF )
    SerTxd("V2.5")
    SerTxd( CR, LF )
#EndIf
However, if this is copied into MacAXEpad it the only statement that is compiled is the 'Pause 100' command, giving 5 bytes of code size.

IfDef1.jpg

If the above code is rewritten as:

Code:
#Define Show_Debug


#IfDef Show_Debug 
    #Terminal 4800
#EndIf

Pause 100

#IfDef Show_Debug
    SerTxd("08M2 DFPlayer controller", CR, LF )
    SerTxd("V2.5")
    SerTxd( CR, LF )
#EndIf
Then the full code is compiled, including the conditional '#Terminal' and 'SerTxd...' commands. Giving 63 bytes of code size.

IfDef2.jpg

It could be that there is a bug in the MaxAXEpad compiler, or in the Windows compiler, or perhaps the Windows compiler is turning a blind eye to the erroneous 'Then', but it has taken me an absolute age to work out why programs that worked correctly in Windows, suddenly didn't on my iMac.

If it *shouldn't* compile, is it possible for it to not compile on both, rather than only on one or the other?
 
Last edited:

Technical

Technical Support
Staff member
#2
PE6 has an additional (much more advanced) pre-processor which seems to be ignoring the 'then' coding error. Obviously the correct solution is to remove the coding error.

However if you want PE6 and MacAxepad to behave the same then turn off the additional preprocessor in PE6 (File>Options>Compiler)
 

tmfkam

Senior Member
#3
Thanks for your reply. At least I know that the 'Then' in a '#IfDef' is incorrect.

I am in the habit of writing 'If ... Then'. It is natural for me to try to use '#IfDef ... Then' which *has* worked, but obviously not in MacAXEpad. The manual I have doesn't specifically mention that the 'Then' will prevent that portion of code compiling even when the '#Define' parameter is true and clearly I've never noticed before.

Here's hoping I remember for next time.
 
Top