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…

[sourcecode language=’cpp’]#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]

2 thoughts on “Conditional breakpoint

  1. 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!

Appreciate your comments...