ID:2404042
 
BYOND Version:510
Operating System:Windows 10 Pro 64-bit
Web Browser:N/A
Applies to:Dream Maker
Status: Open

Issue hasn't been assigned a status value.
Descriptive Problem Summary:
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.
Further experimentation reveals that the name of the first macro can only be as long as (the position of the second macro + the length of the second macro) or, if you will, the last character of the second macro in the #if directive.
That is very confusing, so here are a few examples.
The comment helps with visualizing.
#define SIXTEENCHARACTERS 0
#define THING SIXTEENCHARACTERS
//XTEENCHARACTERS
#if 1 + THING == 0
#endif


#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:
code.dm:7:error: unexpected token: TERS


Adding four more characters will let us compile:
#define SIXTEENCHARACTERS 0
#define THING1234 SIXTEENCHARACTERS
//XTEENCHARACTERS
#if 1 + THING1234 == 0
#endif

(This does, in fact, compile)

This is very weird.