call by value 
Author Message
 call by value

There is a long discussion in comp.lang.fortran about how to get
the effect of call by value in Fortran.  That is, if the caller
wants the argument not to be modified by the callee.  If I remember
right, PL/I guarantees this if the argument is enclosed in
parentheses.  In that case, PL/I considers it an expression, and so
must pass a temporary variable.  It seems that Fortran does not
have this requirement, even with a more complicated expression.

Well, since there is so little traffic here, I thought I would post
this.  First, if someone wants to confirm this is true for PL/I.
My PL/I language reference manual is pretty old.

In trying to understand this in Fortran, I asked about the program
fragment:

       X=A+B
       CALL SUB(A+B)

It seems that Fortran allows passing X by reference to SUB in this
case!

(Please note that I am not trying to start a Fortran vs. PL/I war,
but only peaceful discussion of the two languages.)

-- glen



Sat, 25 Jun 2005 03:53:45 GMT  
 call by value

Quote:

> There is a long discussion in comp.lang.fortran about how to get
> the effect of call by value in Fortran.  That is, if the caller
> wants the argument not to be modified by the callee.  If I remember
> right, PL/I guarantees this if the argument is enclosed in
> parentheses.  In that case, PL/I considers it an expression, and so
> must pass a temporary variable

True.  Also if the argument doesn't match the parameter a dummy is
created, effectively doing call-by-value.

It seems that Fortran does not

Quote:
> have this requirement, even with a more complicated expression.

How would this work in practice, if not the same as PL/I?

Quote:

> In trying to understand this in Fortran, I asked about the program
> fragment:

>        X=A+B
>        CALL SUB(A+B)

> It seems that Fortran allows passing X by reference to SUB in this
> case!

Oh, OK, I see,  Sounds like trouble, though!


Sat, 25 Jun 2005 06:52:37 GMT  
 call by value

Quote:

> In trying to understand this in Fortran, I asked about the program
> fragment:
>        X=A+B
>        CALL SUB(A+B)
> It seems that Fortran allows passing X by reference to SUB in this
> case!

It certainly doesn't pass X.

I don't have ANSI FORTRAN documentation here.  G77 (the FORTRAN
part of the GNU C compiler) seems to behave exactly as PL/I does.

       CALL SUB (A + B)

passes the sum by value (actually passes a temporary by reference),

       CALL SUB (X)

passes X by reference, and

       CALL SUB ((X))

passes X by value (actually passes a temporary by reference).

But I don't know whether G77 is doing standard FORTRAN in this.

--
John W. Kennedy
"The poor have sometimes objected to being governed badly;
the rich have always objected to being governed at all."
   -- G. K. Chesterton, "The Man Who Was Thursday"



Sat, 25 Jun 2005 08:01:28 GMT  
 call by value



Quote:

> > In trying to understand this in Fortran, I asked about the
program
> > fragment:

> >        X=A+B
> >        CALL SUB(A+B)

> > It seems that Fortran allows passing X by reference to SUB in
this
> > case!

> It certainly doesn't pass X.

> I don't have ANSI FORTRAN documentation here.  G77 (the FORTRAN
> part of the GNU C compiler) seems to behave exactly as PL/I does.

>        CALL SUB (A + B)

> passes the sum by value (actually passes a temporary by
reference),

>        CALL SUB (X)

> passes X by reference, and

>        CALL SUB ((X))

> passes X by value (actually passes a temporary by reference).

> But I don't know whether G77 is doing standard FORTRAN in this.

I think it is likely that Fortran compilers would pass a temporary,
but, as I understand it, they are not required to do it.
Optimizers can do strange things sometimes, especially in Fortran.
Personally, I don't think I would be too surprised to see an
optimizer optimize out the () in CALL SUB((X)).   (Much machine
generated code has excessive ()'s, so it isn't unreasonable.)   I
would use X+0, though, as I think that is more likely, though still
not guaranteed, to pass a temporary.

-- glen



Sat, 25 Jun 2005 10:07:04 GMT  
 call by value

Quote:

> In trying to understand this in Fortran, I asked about the program
> fragment:
>        X=A+B
>        CALL SUB(A+B)
> It seems that Fortran allows passing X by reference to SUB in this
> case!

It certainly doesn't pass X.

I don't have ANSI FORTRAN documentation here.  G77 (the FORTRAN
part of the GNU C compiler) seems to behave exactly as PL/I does.

       CALL SUB (A + B)

passes the sum by value (actually passes a temporary by reference),

       CALL SUB (X)

passes X by reference, and

       CALL SUB ((X))

passes X by value (actually passes a temporary by reference).

But I don't know whether G77 is doing standard FORTRAN in this.

--
John W. Kennedy
"The poor have sometimes objected to being governed badly;
the rich have always objected to being governed at all."
   -- G. K. Chesterton, "The Man Who Was Thursday"



Sat, 25 Jun 2005 12:16:54 GMT  
 call by value
in comp.lang.pl1 i read:

Quote:
>Personally, I don't think I would be too surprised to see an
>optimizer optimize out the () in CALL SUB((X)).   (Much machine
>generated code has excessive ()'s, so it isn't unreasonable.)  

unless this special usage is intended for the semantic you ask, in which
case i would expect the standard to say as much.

Quote:
>I would use X+0, though, as I think that is more likely, though still not
>guaranteed, to pass a temporary.

an optimizer that doesn't discard +0 isn't worth the bits it was written
in.

might i ask that this *entirely* fortran oriented discussion be moved to
(restarted in, actually) comp.lang.fortran, i.e., just because you used
available pl/1 semantics as a point of reference doesn't make this a pl/1
discussion.

--
bringing you boring signatures for 17 years



Sat, 25 Jun 2005 13:14:47 GMT  
 call by value
(snip)

Quote:

> might i ask that this *entirely* fortran oriented discussion be
moved to
> (restarted in, actually) comp.lang.fortran, i.e., just because
you used
> available pl/1 semantics as a point of reference doesn't make
this a pl/1
> discussion.

Well, I think it is the most interesting thing discussed here in
the last few months or so.  If you have something more interesting
to discuss, I would be happy to join in.   This one started there,
and has been going on, and may continue to go on.

-- glen



Sat, 25 Jun 2005 14:40:40 GMT  
 call by value
in comp.lang.pl1 i read:

Quote:
>> might i ask that this *entirely* fortran oriented discussion be moved to
>> (restarted in, actually) comp.lang.fortran,
>Well, I think it is the most interesting thing discussed here in
>the last few months or so.  

ah, discuss anything, anywhere.  i see.  sorry, i actually believe in the
topicality of newsgroups.

Quote:
>If you have something more interesting
>to discuss, I would be happy to join in.  

i'd discuss anything pl/1 related, e.g., at the moment i'm fiddling with
mvs and vm under hercules and so i have some interest in likewise fiddling
with some of my older pl/1 programs (nothing production mind you, not that
they could legally or sensibly by run in my personal environment).

--
bringing you boring signatures for 17 years



Sat, 25 Jun 2005 17:12:33 GMT  
 call by value

"those who know me have no need of my name"

Quote:
> in comp.lang.pl1 i read:

> >> might i ask that this *entirely* fortran oriented discussion
be moved to
> >> (restarted in, actually) comp.lang.fortran,

> >Well, I think it is the most interesting thing discussed here in
> >the last few months or so.

> ah, discuss anything, anywhere.  i see.  sorry, i actually
believe in the
> topicality of newsgroups.

(snip)

Well, I was trying to compare Fortran's calling methods to PL/I's.
The fact that PL/I got it right 35 years ago, and Fortran still
hasn't made the discussion pretty short on this side.  It is much
easier to say that something works, than to argue about why it
doesn't.

It seems more topical than {*filter*} enlargement or web hosting, which
seem to also have been posted here lately.

Note that,  historically, PL/I was supposed to be a replacement for
Fortran.  (Also, note that Beta is techinically superior to VHS,
but didn't win the video war.)

-- glen



Sun, 26 Jun 2005 01:43:54 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Scheme values and call-with-values

2. Scheme values and call-with-values

3. Call-by-value vs. call-by-need/name

4. call-with-values & call/cc

5. Call by reference vs. call by value

6. Call by reference vs. call by value

7. returning values through functions calls

8. SubVI call control values.

9. Is call by value necessary?

10. Getting return values from REXX-called C programs

11. Explanation about call-with-values

12. call by value, again

 

 
Powered by phpBB® Forum Software