question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compiler struggles with macro abuse

See original GitHub issue

Project: ParadiseSS13/Paradise @ fdc7d2ce71e527cc0b21a530376aa399975fdefb

Stacktrace:

$ ./DMCompiler.exe "C:\Users\AffectedArc07\Documents\Paradise\paradise.dme"
Compiling paradise.dme
Unhandled exception. System.Exception: Invalid token DM_Preproc_TokenConcat(code\modules\maze_generation\maze_generator.dm:67:19, ##x)
   at OpenDreamShared.Compiler.DMPreprocessor.DMPreprocessor.IncludeFile(String includePath, String file) in C:\Users\AffectedArc07\Documents\GitHub\Misc_Shit\OpenDream\OpenDreamShared\Compiler\DMPreprocessor\DMPreprocessor.cs:line 253
   at OpenDreamShared.Compiler.DMPreprocessor.DMPreprocessor.IncludeFile(String includePath, String file) in C:\Users\AffectedArc07\Documents\GitHub\Misc_Shit\OpenDream\OpenDreamShared\Compiler\DMPreprocessor\DMPreprocessor.cs:line 65
   at DMCompiler.Program.Preprocess(List`1 files) in C:\Users\AffectedArc07\Documents\GitHub\Misc_Shit\OpenDream\DMCompiler\Program.cs:line 106
   at DMCompiler.Program.Main(String[] args) in C:\Users\AffectedArc07\Documents\GitHub\Misc_Shit\OpenDream\DMCompiler\Program.cs:line 28

Offending code:

#define LOG_MAZE_PROGRESS(proc2run, opname) \
do { \
    var/timer = start_watch(); \
    proc2run ;\
    log_debug("\[MAZE] Operation '[opname]' on maze at [##x],[##y],[##z] took [stop_watch(timer)]s"); \
} while (FALSE)

Note: This is a total abuse of macros but works in DM so here we are. Ike told me to.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
wixoaGitcommented, Sep 8, 2021

Some testing with BYOND’s compiler shows that any instance of ##nonexistant_parameter is just replaced with nonexistant_parameter. But only if it’s a macro that takes parameters.

1reaction
AffectedArc07commented, Sep 8, 2021

how is this abuse, this is literally a normal documented part of the preprocessor

A parameter preceded by ## in the macro body is substituted directly, without any spaces

This isnt a parameter.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Compiler struggles with macro abuse · Issue #382
Some testing with BYOND's compiler shows that any instance of ##nonexistant_parameter is just replaced with nonexistant_parameter . But only if it's a macro...
Read more >
What is the worst real-world macros/pre-processor abuse ...
Real-world? MSVC has macros in minmax.h, called max and min , which cause a compiler error every time I intend to use the...
Read more >
How I Learned to Stop Worrying and Love Macros
The first one to compile wins, and the winning branch is used for the rest of the build process.
Read more >
Why aren't macros included in most modern programming ...
I think the main reason is that macros are lexical. This has several consequences: The compiler has no way of checking that a...
Read more >
Worst abuse of the C preprocessor | by Bill Huang
in C, has two types of macros, one is objects- like macro, the other is function-like macro. when the code goes to compilation,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found