We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
#ifdef (Read 793 times)
#ifdef
Sep 30th, 2005, 7:28pm
 
I suppose this is more of a java question than of a processing question, hope you don't mind.

Is there such a thing as compiler directives, or something like that? The equivalent of a "#define" and "#ifdef"?

The reason I'd like it (in case there is another solution) is debugging (having lots of lines here and there that are meant for debugging purposes and that I want to enable and disable without wasting cputime in if statements)...

Thanks in advance
Matteo
Re: #ifdef
Reply #1 - Sep 30th, 2005, 10:56pm
 
You should be able to use static final private boolean DEBUG = true/false;

Then have if (DEBUG) { ... } else { ... } blocks in your code, and the compiler will eliminate the segments that can never possibly be run.

To answer your question, no, Java, does not have anything like that.  If you want to be nutty, you can run a java source through the gcc preprocessor before compiling (I've seen this done in a few places) to use #define, #ifdef, etc., but I hardly recommend this practice.  The Java compiler and vm is generally pretty good at this kind of optimization.

Marcello
Re: #ifdef
Reply #2 - Oct 4th, 2005, 5:35pm
 
cello wrote on Sep 30th, 2005, 10:56pm:
the compiler will eliminate the segments that can never possibly be run.



Really!!!! Does it!!!! Wow........
Re: #ifdef
Reply #3 - Oct 4th, 2005, 11:19pm
 
it's supposed to. in practice it usually does, but it depends on the compiler.
Page Index Toggle Pages: 1