MPLAB debugging question

Thread Starter

Vaughanabe13

Joined May 4, 2009
102
How do you view the return value of a function while you are debugging? FWIW I am using MPLAB with the C18 compiler for C source code and a PICKit3 for programming/debugging. Here is an example - lets say I have this simple function:

Rich (BB code):
int returnNumbers(void)
{
    int num1 = 10;
    int num2 = 5;
    return (num1-num2);
}
I know how to use the watch window to view the contents of variables, but is there any way to directly view the value that is being returned from the function? I know I could do this by creating a new variable and setting it equal to the result, and then use the watch window to get that value, but I don't want to have to restructure my code that way.
 

AlexR

Joined Jan 16, 2008
732
To use a return value of a function you assign the return value to a variable as in the example below. To see the return value all you need to do is watch the value of the variable that gets assigned the function return value.
In the example below you would watch the value of the variable "result".
Rich (BB code):
int returnNumbers(void)
{
    int num1 = 10;
    int num2 = 5;
    return (num1-num2);
}

main()
{
    int result;
    result = returnNubers();
}
 

Thread Starter

Vaughanabe13

Joined May 4, 2009
102
To use a return value of a function you assign the return value to a variable as in the example below. To see the return value all you need to do is watch the value of the variable that gets assigned the function return value.
In the example below you would watch the value of the variable "result".
Rich (BB code):
int returnNumbers(void)
{
    int num1 = 10;
    int num2 = 5;
    return (num1-num2);
}

main()
{
    int result;
    result = returnNubers();
}
Ok, I'm actually using the function in the middle of an equation, which is why it was inconvenient to do it that way, but I suppose I will change it if that's the only way. I was just curious to find out if there was another way.
 
Top