CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    did you ever see if(false) run the if block anyway?

    I'm getting that at the moment.. bugging me for the past few hours. The condition in my IF is evaluating to false, but VS2010 Pro runs the if block anyway. Noone in my team can explain it; this is a new built laptop, windows 7, vs2010 pro and i've just converted the application to 64bit from its 32bit roots. I'm hestiant to even use this dev env any more if it's compiling code that runs when the IF is false, as it this will be used in banking systems..

    Here's a short video, I have the cursor already positioned on the problematic if.. All I do is put the condition into the immediate window immediately before I step over. Condition reports FALSE in the immediate window, but when I choose step over from the debugger menu, it enters the IF regardless.. No prank; any trustworthy soul who uses TeamViewer remote desktop software is welcome to connect to my PC and see this happen for themselves, live.

    Video attached.. It's a SWF video so it's in a zip file along with an HTML file that will act as a container.. just extract the two to your desktop and open the HTML, your browser will play the SWF.. Youre free to examine the HTML beforehand using notepad if you have any concerns about its potential content

    Thanks!
    Attached Files Attached Files
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  2. #2
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: did you ever see if(false) run the if block anyway?

    you know what's even weirder? I just F10'ed again while control was pointing to the "throw exception" line, and no exception was throown, the code just carried on as normal..

    I see different things from the IDE here too:

    Code:
    string s;
    if(false)
      s= "s"; //ide shows error, unreachable code detected
    
    if(false)
      throw new Exception("whatever"); //no IDE warning of unreachable code.. what???
    Last edited by cjard; June 3rd, 2011 at 08:54 AM.
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  3. #3
    Join Date
    Dec 2008
    Posts
    144

    Re: did you ever see if(false) run the if block anyway?

    Sorry, not downloading anything.

    Please pose your real code- the pseudocode you posted isn't really going to help. There are a few possible ways I can think of that you're experiencing this, but I can't be certain without seeing real code.
    Code:
    if (Issue.Resolved)
    {
         ThreadTools.Click();
         MarkThreadResolved();
    }

  4. #4
    Join Date
    Jun 2008
    Posts
    2,477

    Re: did you ever see if(false) run the if block anyway?

    Well, the video shows the if statement being stepped into when the result is false. I tried applying the boolean NOT operator inside of the immediate window and I got an error "not available while Managed only debugging." != worked just fine. Total swing in the dark here, but perhaps the immediate window does strange things with the NOT operator? I know that soudns ridiculous, but have you tried storing the value of your call to Contains() in a variable first and checking what it returns?

  5. #5
    Join Date
    Jan 2010
    Posts
    1,133

    Re: did you ever see if(false) run the if block anyway?

    Maybe it's just some glitch in the graphical representation of the execution flow in the IDE, maybe the if-block doesn't actually get executed?

    If you put a tracepoint there, does it output anything? (Or a breakpoint - does it get hit?)

    Quote Originally Posted by BigEd781 View Post
    I tried applying the boolean NOT operator inside of the immediate window and I got an error "not available while Managed only debugging." != worked just fine. Total swing in the dark here, but perhaps the immediate window does strange things with the NOT operator?
    Yup, "!something" wont work, but "?!something" will.
    The ! symbol is used for SOS commands.

  6. #6
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: did you ever see if(false) run the if block anyway?

    Is it debg or release build? I think it could have something to do with compiler optimization (I bet for this reason) or a glitch in the .pdb file. Clean, rebuild and similar excercises don't help?
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  7. #7
    Join Date
    Jun 2008
    Posts
    2,477

    Re: did you ever see if(false) run the if block anyway?

    Quote Originally Posted by boudino View Post
    Is it debg or release build? I think it could have something to do with compiler optimization (I bet for this reason) or a glitch in the .pdb file. Clean, rebuild and similar excercises don't help?
    I can't imagine that a compiler optimization would change the result of a call to Contains like that. Maybe the source doesn't match the executable?

  8. #8
    Join Date
    Aug 2008
    Posts
    78

    Re: did you ever see if(false) run the if block anyway?

    Just start counting a variable up in "if block"

    if(!map.ContainsKey..)
    {
    someIndex++;
    throw nex exception..
    }

    And you will know the reason. As others also explained, it can be graphical glitch or .exe not matching the code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured