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 62965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:33:31+00:00 2026-05-10T18:33:31+00:00

This may be a matter of style, but there’s a bit of a divide

  • 0

This may be a matter of style, but there’s a bit of a divide in our dev team and I wondered if anyone else had any ideas on the matter…

Basically, we have some debug print statements which we turn off during normal development. Personally I prefer to do the following:

//---- SomeSourceFile.cpp ----  #define DEBUG_ENABLED (0)  ...  SomeFunction() {     int someVariable = 5;  #if(DEBUG_ENABLED)     printf('Debugging: someVariable == %d', someVariable); #endif } 

Some of the team prefer the following though:

// #define DEBUG_ENABLED  ...  SomeFunction() {     int someVariable = 5;  #ifdef DEBUG_ENABLED     printf('Debugging: someVariable == %d', someVariable); #endif } 

…which of those methods sounds better to you and why? My feeling is that the first is safer because there is always something defined and there’s no danger it could destroy other defines elsewhere.

  • 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. 2026-05-10T18:33:31+00:00Added an answer on May 10, 2026 at 6:33 pm

    My initial reaction was #ifdef, of course, but I think #if actually has some significant advantages for this – here’s why:

    First, you can use DEBUG_ENABLED in preprocessor and compiled tests. Example – Often, I want longer timeouts when debug is enabled, so using #if, I can write this

      DoSomethingSlowWithTimeout(DEBUG_ENABLED? 5000 : 1000); 

    … instead of …

    #ifdef DEBUG_MODE   DoSomethingSlowWithTimeout(5000); #else   DoSomethingSlowWithTimeout(1000); #endif 

    Second, you’re in a better position if you want to migrate from a #define to a global constant. #defines are usually frowned on by most C++ programmers.

    And, Third, you say you’ve a divide in your team. My guess is this means different members have already adopted different approaches, and you need to standardise. Ruling that #if is the preferred choice means that code using #ifdef will compile -and run- even when DEBUG_ENABLED is false. And it’s much easier to track down and remove debug output that is produced when it shouldn’t be than vice-versa.

    Oh, and a minor readability point. You should be able to use true/false rather than 0/1 in your #define, and because the value is a single lexical token, it’s the one time you don’t need parentheses around it.

    #define DEBUG_ENABLED true 

    instead of

    #define DEBUG_ENABLED (1) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 52k
  • Answers 52k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer From 'Exceptional C++ style', Item 7: function overload resolution happens… May 11, 2026 at 6:44 am
  • added an answer The error is being reported on the currency comparison h.currency_cd=hxl.currency_cd,… May 11, 2026 at 6:44 am
  • added an answer Take a look at PyGILState_Ensure()/PyGILState_Release(), from PEP 311 http://www.python.org/dev/peps/pep-0311/ Here… May 11, 2026 at 6:44 am

Top Members

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

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.