Re: Problem with Return Value from a Function
- From: glen herrmannsfeldt <gah@xxxxxxxxxxxxxxxx>
- Date: Mon, 02 Jul 2007 11:34:59 -0800
James J. Weinkam wrote:
(snip regarding function return values)
This is not what either the F or the Optimizing compiler did at least for external functions. It was always possible to write an assembly language routine that could be called from PL/I as a function and the location to receive the returned value was passed by reference as an n+1st argument. Function references to assembler routines were only possible if the ASSEMBLER option was *not* used, thus the compiler was unaware the the routine being called was an assembler routine and perforce must have compiled the same linkage it would compile when it was calling a routine written in PL/I. This is all clearly explained in chapter 13 of the programmers guide for the optimizing compiler. I wrote many such functions over the years. You may be thinking of Fortran. It is certainly possible that for internal procedures the optimizer may short circuit some of what it would do for external procedures. You would have to study the compiled code from a particular compiler to find out.
I wrote many PL/I (F) callable assembly routines, but probably
not any were functions. I also called Fortran subroutines,
but again likely no functions.
It is common among other languages and calling sequences to
return integer and float values in registers, and others with
a separate argument. That is, for example, what Systems/C
does. (Though it used R15 for integer and pointer functions,
instead of R0.)
In the discussion at hand, the OP has a (erroneous) function that does not return a result except when its argument is 'B', and he asserts that the the variable to which the returned value is assigned is unchanged in all cases. How can this happen unless the compiler has done what I suggested? If the compiler had created a temporary and subsequently assigned that to A, the final value of A would be whatever random content the temporary contained except when the argument was 'B'.
It is not too hard to have the value accidentally end up in
the right register, but I agree that not assigning at all would
be the easiest way. It is an interesting optimization to realize
that the function return value is assigned directly to a variable.
Consider if the function was used in a more complicated expression.
-- glen
.
- References:
- Re: Problem with Return Value from a Function
- From: glen herrmannsfeldt
- Re: Problem with Return Value from a Function
- From: James J. Weinkam
- Re: Problem with Return Value from a Function
- Prev by Date: Re: Problem with Return Value from a Function
- Next by Date: Re: Problem with Return Value from a Function
- Previous by thread: Re: Problem with Return Value from a Function
- Next by thread: Re: Problem with Return Value from a Function
- Index(es):
Relevant Pages
|
Loading