Page 1 of 1

Preprocessor Defines

Posted: Sat Jan 07, 2023 10:59 pm
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

Re: Preprocessor Defines

Posted: Sat Jan 07, 2023 11:54 pm
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();
}

Re: Preprocessor Defines

Posted: Sun Jan 08, 2023 12:51 am
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