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.?

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,764 questions
Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
1,005 questions
{count} votes

1 answer

Sort by: Most helpful
  1. WayneAKing 4,921 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.