Preprocessor directives, colons, curly brackets & comments

I've just discovered a strange oddity - I can't seem to use the colon (:) to merge multiple lines of code into one, curly brackets to "group" pieces of code in the editor, or use comments on the same line when using preprocessor directives.

The following doesn't work:
Code:
#IF number > 1:    put var1 + 4, 150            :#ENDIF
While the following does:
Code:
#IF number > 1
            put var1 + 4, 150         
#ENDIF
In addition, the following doesn't work:
Code:
#DEFINE number 8                        'Number of LDRs connected (starts at 1)
but does if I remove the comment.

Finally, having {#IF generates an error where the pre-processor cannot find the #IF's corresponding #ENDIF. You have to move the brackets to another line to clear the error. Confusinly, this does not apply when you have #ENDIF}...

The errors are as follows:
Code:
#IF number > 1
^
Syntax error on line 75 at position 1

Error: 8                        ;Number of LDRs connected (starts at 1) is not a numeric value, try #IFDEF instead of #IF?
Code:
#IF number > 1:    put var1 + 4, 150            :#ENDIF
^
Syntax error on line 79 at position 1

Error: put var1 + 4, 150            :#ENDIF is not a numeric value.
It would appear, in other words, that pre-processor directives don't recognise the colon or comment symbols (' / ; / REM) in the same way the compiler does - this isn't a problem for me, per se, as I've already found the solutions, but I couldn't find this listed anywhere in the documentation after a quick search. So hopefully this post will be of some help to someone in the future.
 

techElder

Well-known member
The key is that you are trying to do this with directives. The same things that work in program code don't exactly work in directives.
 
The key is that you are trying to do this with directives. The same things that work in program code don't exactly work in directives.
Precisely my discovery :) As I said, it's not much of a problem for myself, as I've found the solution, but as it doesn't seem to be documented elsewhere this thread will hopefully prove to be useful to other beginners who make the same mistakes
 

hippy

Technical Support
Staff member
The behaviour is down to implementation of the pre-processor in that #IF does not allow a colon (:) to follow it, and the hash (#) must be the first character on the line, the #DEFINE definition being everything to end of line.

As to the curly bracket folding; that's probably a part of the editor screen component handling which we have no control over. I would have to check that.

I will take a look at the documentation to see if it can be improved where the behaviour is not detailed..
 

Aries

New Member
I did refer to the #DEFINE problem here ...
... having met a similar problem

In fact, I have since exploited it to deal with making SERTXD active or not ...
Code:
#DEFINE sxrtxd SERTXD
or
#DEFINE sxrtxd ' SERTXD
...
sxrtxd("Hello world")
is easily legible in the code and easily switched on and off with the DEFINE. You have to be a bit more creative with multi-line SERTXDs
 
Last edited:
Top