RETURN Value of function 
Author Message
 RETURN Value of function

Hello,

I would like to get the contents of a return-value in a function through
the de{*filter*}, how can I get it ?

double Fakultaet(int Zahl)
{
   if (Zahl > 1)
   return(Zahl*Fakultaet(Zahl-1));        // How can I get the actual
contents of the 'return'-value ?
    else
    return(1);

Quote:
}

Thanks for answer
Oliver



Mon, 03 Feb 2003 03:00:00 GMT  
 RETURN Value of function

Quote:

> I would like to get the contents of a return-value in a function through
> the de{*filter*}, how can I get it ?

> double Fakultaet(int Zahl)
> {
>    if (Zahl > 1)
>    return(Zahl*Fakultaet(Zahl-1));   // How can I get the actual
>                                    contents of the 'return'-value ?
>     else
>     return(1);
> }

Some de{*filter*}s will show the return value, some will not.  Some
compilers put the return value in a register you can examine, some
will not.

I would recode this as:

double Fakultaet(int Zahl)
{
   double rc;

   if (Zahl > 1) {
     rc = Zahl*Fakultaet(Zahl-1);
   }
   else {
     rc = 1;
   }
   return rc;

Quote:
}

Then you can set a breakpoint at the return and examine rc.  Any
de{*filter*} should support this.
--

--



Tue, 04 Feb 2003 03:00:00 GMT  
 RETURN Value of function

Quote:

> Hello,

> I would like to get the contents of a return-value in a function
> through the de{*filter*}, how can I get it ?

Create a variable and the return value to it, then return that
variable.  See below.

double Fakultaet(int Zahl) {
  if (Zahl > 1) {
    double val = Zahl * Fakultaet(Zahl-1);
    return val;  /* Place a breakpoint here to see the return value. */
  }
  else
    return(1);

Quote:
}

--
Rex Barzee
Hewlett-Packard Unix Development Lab
--



Tue, 04 Feb 2003 03:00:00 GMT  
 RETURN Value of function

Quote:

> I would like to get the contents of a return-value in a function through
> the de{*filter*}, how can I get it ?

We don't know.  Read the documentation for your de{*filter*}.  If you
still have questions, try a newsgroup relevant to whatever system
you're using; they're much more likely to be able to help you than we
are.

And *please* don't post HTML to discussion groups.

(Hello?  Moderator?)

[very sorry.  my mailer is so clever that it sometimes hides the HTML from
 me. -mod]

--

San Diego Supercomputer Center           <*>  < http://www.*-*-*.com/ ~kst>
Welcome to the last year of the 20th century.
--



Tue, 04 Feb 2003 03:00:00 GMT  
 RETURN Value of function

Quote:

> Hello,
> I would like to get the contents of a return-value in a function through
> the de{*filter*}, how can I get it ?

Impossible to tell, without further details. It's not really a
language issue, at all, but a compiler issue.  To be precise, this is
for the documentation of your particular de{*filter*} to answer.
--

Even if all the snow were burnt, ashes would remain.
--



Tue, 04 Feb 2003 03:00:00 GMT  
 RETURN Value of function
Oliver,

Just use a temp{*filter*}value to store the return-value of the expression:

int temp_value;    // declare it first

temp_value = Fakultaet(Zahl - 1)

then replace the return statement with:

return (Zahl * temp_value);

Rob

Hello,
I would like to get the contents of a return-value in a function through the
de{*filter*}, how can I get it ?
double Fakultaet(int Zahl)
{
   if (Zahl > 1)
   return(Zahl*Fakultaet(Zahl-1));        // How can I get the actual contents of the 'return'-value ?
    else
    return(1);

Quote:
}

Thanks for answer
Oliver

--



Tue, 04 Feb 2003 03:00:00 GMT  
 RETURN Value of function

Quote:

> Hello,

> I would like to get the contents of a return-value in a function
> through the de{*filter*}, how can I get it ?

Create a variable and the return value to it, then return that
variable.  See below.

double Fakultaet(int Zahl) {
  if (Zahl > 1) {
    double val = Zahl * Fakultaet(Zahl-1);
    return val;  /* Place a breakpoint here to see the return value. */
  }
  else
    return(1);

Quote:
}

--
Rex Barzee
--



Tue, 04 Feb 2003 03:00:00 GMT  
 RETURN Value of function

Quote:

> I would like to get the contents of a return-value in a function
> through the de{*filter*}, how can I get it ?

> double Fakultaet(int Zahl)
> {
>    if (Zahl > 1)
>    return(Zahl*Fakultaet(Zahl-1));        // How can I get the actual
> contents of the 'return'-value ?
>     else
>     return(1);
> }

Shouldn't somebody tell Oliver about using "diagnostic statements" and
turning them on and off with #define and #undef rather than relying
on the de{*filter*}? If there are no other volunteers ...

The basic idea is to conditionally include debugging code using
preprocessor directives. In the example below, substituting
"#undef DEBUG" for "#define DEBUG" causes any debugging code, enclosed
between "#ifdef DEBUG" and "#endif", to vanish.

There are many variations on the basic scheme presented here which are
more flexible and complex, but in it's most easily understood form it
can look something like this:

----- BEGIN EXAMPLE -------------------------------------------------
#include <stdio.h>

/*
 * Turn debugging output on. To turn off debugging output
 * replace this line with #undef DEBUG
 */
#define DEBUG

double Fakultaet(int Zahl);

/* Whatever other function prototypes, etc, are required here */

int main( int argc, char *argv[] )
{
    double rv;
    int Zahl;

    /* Presumably, something to get a value for Zahl */

    rv = Fakultaet( Zahl );

#ifdef DEBUG
    fprintf( stderr, "Fakultaet(%d) returned: %lf\n", Zahl, rv );    
#endif

    /* Other stuff */
    return 0;

Quote:
}

/*
 * Although "premature returns" are regarded as bad practice
 * by many, they're a very common idiom. The "else" is entirely
 * redundant. Also, I'll indulge my preference for curly brackets
 * even when they're not required:
 */
double Fakultaet( int Zahl )
{
    if( Zahl > 1 ) {
        return Zahl*Fakultaet(Zahl-1);
    }
    return 1;
Quote:
}

----- END EXAMPLE ----------------------------------------------------

Appropriate use of this method (or its variants) can have great
advantages. It allows you to find errors quickly --- by putting
a debugging statement where you "know it works" and another where you
"know it doesn't".

You can add another one in the middle between the two, retest, and
continue the process of inserting a new debugging statement between a
debugging statement which produces "expected" output, and one that
produced "bad" output. In this way, you quickly find out where the
problem in your code is. In essence, you are doing a binary search
for the bug.

Finally, you can "turn off" all of the debugging code with a single
change.

It is also common practice to have debugging code that is included in
the final program, but only produces output on error. In fact, this is
standard practice. There are many different ways that this can be
achieved, but reading about "assert.h" and *always* checking the
return values of functions which return something is a good place to
start.

HTH,

Emmet.
--



Fri, 07 Feb 2003 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Returned value from function

2. Question about returning values of functions

3. Returned value from function

4. RETURN Value of function

5. Accessing return value from function

6. Compiler bug? (return values from functions)

7. Returning values from functions

8. returning values from functions

9. how to watch the return value of function

10. How to use "Evaluate" method for the return value of function?

11. How to "Evaluate" method for the return value of function?

12. function parameters and return values aren't changed by function call

 

 
Powered by phpBB® Forum Software