Preprocessor Defines

Post Reply
UrbanCyborg
Posts: 599
Joined: Mon Nov 15, 2021 9:23 pm

Preprocessor Defines

Post by UrbanCyborg »

How do you insert #define statements into a VM project? The places it would make sense to do so are all under the editor's control. I'd like to put logging code into #ifdef blocks so I don't have to always find and comment it out.

Reid
Cyberwerks Heavy Industries -- viewforum.php?f=76
ColinP
Posts: 951
Joined: Mon Aug 03, 2020 7:46 pm

Re: Preprocessor Defines

Post by ColinP »

I might well be misunderstanding your question but if all you want is to switch debugging code on and off...

Java doesn't have a preprocessor like C or C++ as there is no real need.

Java compilers do flow analysis therefore they simply do not generate code for statements that will never execute, so you can just use regular if statements instead of #if without there being any runtime overheads.

So you might want to have the following...

Code: Select all

final boolean DEBUG = false;
Then you can just write...

Code: Select all

if( DEBUG )
{
	doSomething();
}
UrbanCyborg
Posts: 599
Joined: Mon Nov 15, 2021 9:23 pm

Re: Preprocessor Defines

Post by UrbanCyborg »

Thanks, Colin. I got misled by my editor, which for some reason has macro entries for C-style preprocessor pragmas. Never mind. :oops:

Reid
Cyberwerks Heavy Industries -- viewforum.php?f=76
Post Reply

Return to “Module Designer”