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

  • SEARCH
  • Home
  • 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 7773009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:01:06+00:00 2026-06-01T17:01:06+00:00

At school I was often taught that preprocessor statements can easily go haywire, since

  • 0

At school I was often taught that preprocessor statements can easily go haywire, since the strings you define, eg:

#define PI 3.1415926

are substituted every where in your code, leading to weird substitutions when a variable name contains the string PI.

Therefore, when debugging, I steer away from the following approach:

#define _DEBUG
...
#ifdef _DEBUG
    // debug code
#endif
...

but tought it would be “safer” to use:

const static bool DEBUG = true
int main()
{
    ...
    if(DEBUG){ /* debug code*/ }
    ...
}

This works well but I was wondering what, in comparison to the preprocessor statement approach, the overhead is at run-time for this approach? With the preprocessor approach everything happens before compilation,so no run-time overhead is to be expected.

I know that the overhead for a simple if-statement is pretty much neglectabe, yet this doesn’t hold when it is put deep in to some nested loops that run for a large number of times (small things add up to big things).

Does the compiler recognize the fact that DEBUG is const static and hard-code this into the executable, already enabling or disabling the debug code at compile-time? What makes me suspect this is that the other day, when working in some unrelated code, the compiler warned me about some part of the code being obsolete because the if-statement surrounding it would never become true (if I remember correctly).

  • 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-06-01T17:01:08+00:00Added an answer on June 1, 2026 at 5:01 pm

    It’s impossible to give a hard guarantee: it is up to each individual compiler what it does with the code you feed it.

    However, any real-world compiler will optimize this out for you. It is one of the simplest, most trivial optimizations that exist, and most compilers would probably do it even if you disable optimizations.

    It just doesn’t make sense to generate code for what’s essentially if (true).

    So there should be zero overhead at runtime.

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

Sidebar

Related Questions

When in school it was often a requirement to flowchart the little programs that
Our school's ERP has a nasty database structure to it and since it is
Very often you have a function, which for given arguments can't generate valid result
Can anyone recommend any good material that seeks to provide a real world perspective
So, at my school theyy have this service which tells you that your request
As a school project we've created a C# XNA 4.0 Game that runs perfectly
For School I have been given a class interface to define my own array
I have a small school assignment. My output is not correct. Can you see
For a school project we have to create an evaluation website that requires a
I currently have a download site for my school that is based in .net.

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.