Error using #ifdef within macro (Picaxe Editor 6.0.8.7)

PhilHornby

Senior Member
Code:
[COLOR=navy]#macro [/COLOR][COLOR=black]GivesError[/COLOR]
[COLOR=navy]#ifdef [/COLOR][COLOR=black]x
      [/COLOR][COLOR=purple]b0 [/COLOR][COLOR=darkcyan]= [/COLOR][COLOR=navy]1
#else
      [/COLOR][COLOR=purple]b0 [/COLOR][COLOR=darkcyan]= [/COLOR][COLOR=navy]2
#endif
#endm[/COLOR]
Running "CHECK SYNTAX" against that code fragment gives: EditorError1.png

Indenting the "#ifdef" changes the error message to the "#else" statement instead ...

Code:
[COLOR=navy]#macro [/COLOR][COLOR=black]GivesError
      [/COLOR][COLOR=navy]#ifdef [/COLOR][COLOR=black]x
      [/COLOR][COLOR=purple]b0 [/COLOR][COLOR=darkcyan]= [/COLOR][COLOR=navy]1
#else
      [/COLOR][COLOR=purple]b0 [/COLOR][COLOR=darkcyan]= [/COLOR][COLOR=navy]2
#endif
#endm[/COLOR]
Almost implying that the indentation is important: EditorError2.png

It's not though - no combination of indentations remove the error (nor does removing the #else).

I'm assuming that the "#ifdef" construct is not allowed within a macro. By design? -- if so, more meaningful error message please :)
 
Last edited:

Technical

Technical Support
Staff member
The preprocessor runs before the compilation, and macros are expanded as it runs.
However it is single pass preprocessor, so you cannot expand the macro AND run other preprocessor directives both at the same time.

Or in other words you cannot use other different preprocessor directives inside a macro. Hence the error msg is correct, the prepocessor will only accept #endmacro as the next preprocessor directive after #macro
 
Top