Reputation: 67380
Using C# in Visual Studio 2008 and stepping through a function in the debugger I get to the end of a function and am on the final curly brace } and about to return. Is there a way to find out what value the function is about to return?
This is necessary if the return value is calculated such as:
return (x.Func() > y.Func());
Upvotes: 4
Views: 482
Reputation: 26341
I'd actually recommend refactoring the code to put the individual function returns in local variables. That way, yourself and others don't have to jump through hoops when debugging the code to figure out a particular evaluation. Generally, this produces code that is easier to debug and, consequently, easier for others to understand and maintain.
int sumOfSomething = x.Func();
int pendingSomethings = y.Func();
return (sumOfSomething > pendingSomethings);
Upvotes: 1
Reputation: 20724
I am still using VS 2003 with C++, so this may or may not apply. If you use the "auto" tab (near the "locals" and "watch" tabs), it will tell you the return value of a function once you return.
Upvotes: 2
Reputation: 47492
It's a little low level, but if you switch to disassembly then you can single step through the instructions and see what the return value is being set to. It is typically set in the @eax register.
You can place a breakpoint on the ret instructions and inspect the register at that point if you don't want to single step through it.
Upvotes: 4
Reputation: 9821
You can put
(x.Func() > y.Func())
in a watch window to evaluate it, and see the result. Unless the statement is
return ValueChangesAfterEveryCall();
you should be fine.
Upvotes: 2