Visual Studio 2019 C++, how to know which return statement (out of multiple return statements in current function) exited the current function

pasha 1 Reputation point
2020-08-23T20:56:50.307+00:00

I'm debugging a C++ function in Visual Studio 2019 and there are multiple return statements in it.
I want to know which return statement exited the current function.
Right now I'm adding breakpoints to all the return statements and continuing the execution the execution.
Is there a simpler way.?

Developer technologies | Visual Studio | Debugging
Developer technologies | C++
{count} votes

1 answer

Sort by: Most helpful
  1. WayneAKing 4,931 Reputation points
    2020-08-23T23:55:52.647+00:00

    Further to Barry's suggestion to use a print before each return, note that
    you can use the predefined macro LINE to display the source code line
    number. So code such as:

    std::cout << __LINE__ + 1 << '\n';
    return n;
    

    will display the source line number of the return statement.

    If you don't want to clutter up the stdout display with these line numbers,
    or if you don't have a console attached to your program, you can use
    OutputDebugString (OutputDebugStringA, OutputDebugStringW) to show the
    line numbers in the Output Window of the Debug session.

    • Wayne
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.