Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return value of a function in Visual studio

HI,

I am very much new to using Visual studio.

I am trying to debug an application. where i came across a statement like below:

double tmp = 
myPart->bat_qty() * timeFactor / myPart->AUB() * myPart->UCost * myAIM->param->myAnalysisParams->wd_year;

in VS when put the cursor at

timeFactor
myPart->UCost
myAIM->param->myAnalysisParams->wd_year

it shows the corresponding values.But Not of the values returned by

myPart->bat_qty()
myPart->AUB()

what is the easiest way to find the values returned by those functions. Apologies if this appears to be a cliche kind of a query.But i am completely new to VS. I need a better way to find the values returned without editing the files for storing the values in some temporary variables.i mean i sould not edit the files.

like image 841
Vijay Avatar asked Jan 18 '11 13:01

Vijay


People also ask

How do I see return value in Visual Studio?

View return values for functions If the window is closed, use Debug > Windows > Autos to open the Autos window. In addition, you can enter functions in the Immediate window to view return values. (Open it using Debug > Windows > Immediate.)

How do you get a return value from a function?

To return a value from a function, you must include a return statement, followed by the value to be returned, before the function's end statement. If you do not include a return statement or if you do not specify a value after the keyword return, the value returned by the function is unpredictable.

How do you find the return value?

There are 2 places where we can see the method return value: In the Debugger Immediate window, using the $ReturnValue keyword. To open the Immediate window while debugging, choose Debug -> Windows -> Immediate (or press keyboard shortcut: Ctrl + Alt + I). In the Debugger Autos window.

Does return in function print the value?

The return statement does not print out the value it returns when the function is called. It however causes the function to exit or terminate immediately, even if it is not the last statement of the function. Functions that return values are sometimes called fruitful functions.


1 Answers

In VS 2010 you can put the breakpoint at the function call site and activate the "Autos" Window (if the Autos window is not visible you can make it visible from Debug -> Windows -> Autos Ctrl + Alt + V, A). In the Autos Window after you step over the function call (F10) you will see something in the lines of:

Name Value Type

[Func] Returned [Return Value] [Return Type]

where [Return Value] and [Return Type] are the appropriate return value and type for your function named [Func].

I hope this helps.

This has the advantage that you do not have to edit the code. The disadvantage I see is that if the returned type is complex you cannot expand it and inspect its attributes like you can do if you assign the return value to an automatic variable. However for simple structs the return value is expanded to something like this: {var1=[val1], var2=[val2]...} where var1, var2 are the attributes of the struct.

As far as I know the Autos Window is there (and did the same thing) back in VS 6.0 so this applies to VS 2005 too I guess (someone asked about VS 2005 too).

like image 110
ds27680 Avatar answered Sep 23 '22 19:09

ds27680