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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:13:55+00:00 2026-05-18T03:13:55+00:00

As the question explains: I would like to add some debugging code that only

  • 0

As the question explains: I would like to add some debugging code that only runs when the program is attached to the debugger. I would imagine that this flag or pre-processor variable would be different for every compiler…

In my case I am using Microsoft Visual Studio 2010 with C++.

I also use Eclipse on another computer at home running Ubuntu 10.4 and again in C++.

  • 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-18T03:13:56+00:00Added an answer on May 18, 2026 at 3:13 am

    This question could mean 1 of 2 things:

    1. Code that only runs based on the build configuration (e.g. Release vs. Debug)
    2. Code that only runs when the debugger is attached

    Based on build configuration

    This can be solved by using the pre-processor macro relevant to your compiler (e.g. _DEBUG for the Win32 CRT).

    Based on whether debugger is attached

    This can be solved in several different ways.

    Global boolean variable

    One way I find is to define a global boolean variable which is initialised to false, like this:

    bool gDebug = false;
    

    And when I have attached to the code with my debugger, break in the code and override gDebug with true via the Watch window. Then you can add code that runs conditionally if this is set is true:

    if (gDebug)
    {
        // Debugger is attached, so run this code
        // ...
    }
    

    Registry key

    Define a DWORD registry value which is initialised to 0, but you can override to 1 via the registry editor.

    You then make your debug code conditional on this registry value being set to 1. This may be a better alternative as you can control this value externally without have to break in your debugger to set a global variable at the appropriate time.

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

Sidebar

Related Questions

the question explains it all. For instance, if I have a NSDictionary like this
I'm want to make code that reads assembly instructions (x86 only) and recreates them
An earlier question on the subject explains that you can request a reboot with
Let me explain the application. Before starting my question, I would like to say
I would like to have a variable defined in my web.config that I can
Not all that sure how I would describe this question, so I'll jump right
So my quick question to everyone is, would anyone be able to explain to
First of all, I am a WEB NOOB. Which probably explains this question. Anyway,
This question (along with its answer) explains why you can't easily bind a DataGridView
The title pretty much explains the meat of the question. I'm debating on starting

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.