Re: GCC Differences

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 
> float toot(int x, float y) {
>    if (y == 20) {
>       return y;
>    } else {
>       toot(x, x*y);
>    }
> }
The code itself is broken as other have said you need:

	return(toot(x, x*y));

The reason it ever did work has to do with the internal mechanics
of how function calls are actually implemented.  I am not an expert
on this but have a very vague understand.  Essentially, though,
the return value of a function is pushed onto the stack, and the 
calling function's responsibility is to pop that value off of the 
stack.  If on the other hand the calling function:

	- neglects to pop the return value off of the stack.
	- does nothing else that would alter the stack (call another 
	  function.
	- does not return a value when it exits (thus pushing its 
	  own return value on the stack).

Then the return code from the function whose value was not put 
on the stack ends up being taken as the return code of the function 
that called that function (things work this way with shell script 
functions but its documented and supposed to be a desirable behavior).

The bottom line is that some compilers allow this to happen, and others 
may not, and in any case you should never depend on implementation
details of the compiler and the function calling semantics of
a platform (unless your writting in assembly (-;).  

The short answer, though is as others said, use -Wall.

Cheers..james



_______________________________________________
Redhat-devel-list mailing list
Redhat-devel-list@redhat.com
https://listman.redhat.com/mailman/listinfo/redhat-devel-list

[Index of Archives]     [Kernel Newbies]     [Red Hat General]     [Fedora]     [Red Hat Install]     [Linux Kernel Development]     [Yosemite News]

  Powered by Linux