I want to use a preprocessor macro inside an #if directive.
The value of this macro is obtained from a second macro.
If the name of the second macro is longer than some seemingly arbitrary limit, the compiler fails with a confusing error message.
Numbered Steps to Reproduce Problem:
- Try to compile the following code
Code Snippet (if applicable) to Reproduce Problem:
Demo project is available here: https://github.com/DamianX/junk/raw/master/test6.zip
#define SHORTTHING 0
#define STUFF SHORTTHING
#if SHORTTHING == 0
#endif
#define LONGER_NAME_OF_THING 0
#define LONGER_STUFF LONGER_NAME_OF_THING
#if LONGER_STUFF == 0
#endif
Expected Results:
This should compile.
Actual Results:
It doesn't compile. Specifically, the first set of macros (SHORTTHING and STUFF) works fine, the second set of macros (LONGER_NAME_OF_THING and LONGER_STUFF) don't.
loading test6.dme
test6.dm:10:error: unexpected token: HING
test6.dmb - 1 error, 0 warnings
Does the problem occur:
Every time? Or how often? Every time.
In other games? N/A
In other user accounts? N/A
On other computers? Yep.
Did the problem NOT occur in any earlier versions? If so, what was the last version that worked? Reproduced this under windows 10 x64 with BYOND versions 510.1347 and 512.1452. Also reproduced this under Ubuntu x64 with BYOND version 512.1448.
Workarounds:
Shorter names seem to work, for some reason.
That is very confusing, so here are a few examples.
The comment helps with visualizing.
#if 1 + THING == 0
Here, THING, referred to as the second macro, is encountered at position 9 of the string, and is 5 characters long, so our string can only be 9+5 characters long.
Which means SIXTEENCHARACTERS doesn't compile, as evidenced by the error message produced:
Adding four more characters will let us compile:
(This does, in fact, compile)
This is very weird.