Jump to content

Conditional code inclusion at build time


Drokle

Recommended Posts

I'm new to Java programming, although luckily it's similar enough to C/C++ that I am so far having no difficulties.

However, one thing I used a lot in C is the preprocessor, which allows you to specify build options in a way that makes it easy to switch on or off different builds. The preprocessor runs at build time before the compiler and you can pass it options to do certain things, most commonly define substitution macros.

As an example, you have something like

#define __DEBUG_BUILD__
//#undef __DEBUG_BUILD__ /* Switch debugging on or off at build time */
#ifdef __DEBUG_BUILD__
#define log_info( /*  Whatever variables you want */ ) /* Some code to substitute for log_info */
#else
#define log_info /* log_info is now a blank expression - no debug info will be logged */
#endif

Does Java have something similar to the C preprocessor?

Link to comment
Share on other sites

Java does not have such a thing as It's a higher level language.  Just declare it as a (public)static final and boom, there  you go
Reason: Java doesn't have a precompiler. I know it will be annoying to wrap your head around but eventually, you'll get used to it. You could make your own version of it using classes and all, but it won't make any difference since the won't preprocess it anyway... 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...