Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6997005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:13:44+00:00 2026-05-27T20:13:44+00:00

I have a system where I specify on the command line the verbosity level.

  • 0

I have a system where I specify on the command line the verbosity level. In my functions I check against what was specified to determine if I enter a code block or not:

#ifdef DEBUG
if (verbose_get_bit(verbose_level_1)) {
    // arbitrary debugging/printing style code generally goes in here, e.g.:
    printf("I am printing this because it was specified and I am compiling debug build\n");
}
#endif

I’d like to make this less tedious to set up, so here’s what I have so far:

// from "Verbose.h"
bool verbose_get_bit(verbose_group_name name); // verbose_group_name is an enum
#ifdef DEBUG
#define IF_VERBOSE_BIT_D(x) if (verbose_get_bit(x))
#else // not debug: desired behavior is the entire block that follows gets optimized out
#define IF_VERBOSE_BIT_D(x) if (0)
#endif // not debug

Now, I can do this:

IF_VERBOSE_BIT_D(verbose_GL_debug) {
    printf("I don't want the release build to execute any of this code");
    glBegin(GL_LINES);
    // ... and so on
}

I like this because it looks like an if-statement, it functions as an if-statement, it’s clear that it’s a macro, and it does not get run in the release build.

I’d be reasonably sure that the code will get optimized out since it will be wrapped in a if(false) block but I would prefer it if there was some way I can get the preprocessor to actually throw the entire block away. Can it be done?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:13:45+00:00Added an answer on May 27, 2026 at 8:13 pm

    I can’t think of a way to do it without wrapping the entire block in a macro.

    But this might work for your purposes:

    #if DEBUG
    #define IF_VERBOSE_BIT_D(x) {x}
    #else
    #define IF_VERBOSE_BIT_D(x)
    #endif
    
    IF_VERBOSE_BIT_D(
        cout << "this is" << endl;
        cout << "in verbose" << endl;
        printf("Code = %d\n", 1);
    )
    

    Indeed the compiler should be able to optimize out an if (0), but I often do something similar to this when the code inside the block will not compile at all when not in debug mode.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a system where customers, mainly European enter texts (in UTF-8) that has
Is it possible to specify extra header files to include from the command line
I have a very simple command line Java application that I wish to port
My question concerns using aidl.exe (on a Windows system) from the command line. This
When using ImageMagick from the command line, how do I specify a bold or
I have a Java main application with somewhat complex command line arguments. These arguments
We have system here that uses Java JNI to call a function in a
I have System.Collections.Generic.Dictionary<A, B> dict where A and B are classes, and an instance
Let's say we have system A comprising a MySQL database, with several tables. After
I have a system that combines the best and worst of Java and PHP.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.