CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Odd code path

  1. #1
    Join Date
    Sep 2003
    Location
    England
    Posts
    129

    Odd code path

    Hello all,

    Could someone please confirm that I am not going mad here. The file concerned is up to date and matches the binary that is running:

    Code:
    try
    {
        if(!p || !ValidValue(pHelper, pObject))
        {
             return true;
        }
    } // HERE
    catch(...)
    {
        AfxMessageBox("report");             
        return true;   // THERE
    }
    When I am debugging and I get the line above (HERE) I single step and land on THERE.

    I was expected it to miss the catch's brackets out completely, or at least hit the message box. Why would it jump to THERE?

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Odd code path

    Is this an optimized build? Both the return true; statements end the function and return the same value, hence the compiler easily can contract them into a few common machine instructions during optimization.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  3. #3
    Join Date
    Sep 2003
    Location
    England
    Posts
    129

    Re: Odd code path

    Thanks for the tip.

    I just checked and the build parameters for optimisation is: Disabled (/Od)


  4. #4
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Odd code path

    Can you post the disassembly of that code fragment (or perhaps the entire function if it's not too large)?
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  5. #5
    Join Date
    Sep 2003
    Location
    England
    Posts
    129

    Re: Odd code path

    How do I do that?

    Also, I have tried adding extra lines in etc and the same thing always happens.

    The code ALWAYS jumps to the return true. The code then does not actually return from the function but carries on to the next lines.

  6. #6
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Odd code path

    Quote Originally Posted by SteveTaylor View Post
    How do I do that?

    Also, I have tried adding extra lines in etc and the same thing always happens.

    The code ALWAYS jumps to the return true. The code then does not actually return from the function but carries on to the next lines.
    You are either

    1) Debugging source code that does not match the executable you're running. In other words, the source code the debugger sees is newer or older than the executable that's running.

    Check that you're running the executable you think you're running. The usual cause of this is that you may have multiple versions of that executable, and you're starting up another version of the EXE instead of the one you just built.

    OR

    2) Running an optimized build.

    If you need convincing, put an output statement in one of the functions you know will be called. If it's a console program and you use cout, you will see the message. If you don't see the message, then item 1) is the issue.

    Regards,

    Paul McKenzie

  7. #7
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Odd code path

    Quote Originally Posted by SteveTaylor View Post
    How do I do that?
    While debugging, you can simply select part of the disassembly with the keyboard or mouse and copy it to the clipboard like any other text. If you don't have the disassembly window open, you get it by pressing Alt+8 (not Alt+F8) or via the menu under Debug -> Windows.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Tags for this Thread

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