Breakpoint when variable takes on a certain value.

Posted by Mick on Stack Overflow See other posts from Stack Overflow or by Mick
Published on 2010-03-22T17:09:05Z Indexed on 2010/03/22 17:11 UTC
Read the original article Hit count: 229

Filed under:
|
|

I have something analogous to the following code...

void function(int x)
{
    // complicated operation on x
    blah 
    blah
}

It all appears to be working fine except when x happens to be a particular value, say "273". But x being 273 is a rare event, 99.999% of the time it is some other value. Now I wish to observe the events when this function is called with x=273, so I would like to insert a breakpoint that gets hit only with x is that value. Perhaps I could do it like this:

void function(int x)
{
    if (x == 273)
    {
        // put breakpoint on this line.
    }
    // complicated operation on x
    blah 
    blah
}

The problem is that presumably the compiler will optimise away this "if" statement because it doesn't do anything. So my question is what should I put within the "if" statement to to make sure it gets compiled in to something... or should I be tracing the x==273 case in some completely different way.

© Stack Overflow or respective owner

Related posts about visual-studio-2008

Related posts about c