Home > C++, VC++ > Conditional breakpoint

Conditional breakpoint

How to set a conditional breakpoint

Add this code to your common include or some file where it’s meant to be used…

#ifdef _DEBUG
    #define CBREAK( condition ) if(( condition )){ _asm int 3; }
#else
    #define CBREAK( condition )
#endif

//How to use this macro…
void SomeFunction()
{
    for( int nIndex = 0; nIndex < 100; ++nIndex )     {         ...         CBREAK( nIndex == 32 );     } }[/sourcecode]

Advertisements
  1. January 8, 2008 at 3:45 am

    Thanks George!

  2. george moor
    January 7, 2008 at 9:22 pm

    I enjoyed this hint very much, as it will adapt so well to console use for printing out a debug message. I’ve never come across hash define used to set a line (which can vary!) to **nothing**. I generally put up with an avalanche of checks being output to the console, or else have to manually intervene with the code. Now I hope one commment will silence an entire module of varied “print and wait” messages 🙂

    Thanks Nibu, your c and console tips are a breath of fresh air to me!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: