comp.lang.ada
 help / color / mirror / Atom feed
* Parameter modes
@ 1988-11-15 13:05 Dale Gaumer
  1988-11-18 14:06 ` Robert Firth
  1988-11-21 23:46 ` Michael Murphy
  0 siblings, 2 replies; 8+ messages in thread
From: Dale Gaumer @ 1988-11-15 13:05 UTC (permalink / raw)



     I would like to explore the possibility of using pass-by-reference for
non-scalar parameters with mode "out" or "in out". The LRM, in section 6.2(7),
states quite clearly that pass-by-copy is not required. However, the compilers
with which I am familiar use pass-by-copy. Since this is a serious performance
problem, I questioned several compiler vendors about why they chose to use
pass-by-copy.  The unanimous reply was, that the LRM requires pass-by-copy. 
     It was further explained to me that the LRM requires parameters to be
reset to the initial value when an exception occurs within the subprogram. And
the only way to ensure this result, is to use pass-by-copy. However the LRM,
in section 6.2(12), states that "the final value of an actual parameter of
such a type can be either its valued before the call or a value assigned to
the formal parameter during the execution of the subprogram". 
     A further explanation is that, an exception may occur during an
assignment of an array or record. If this were to occur, the assignment would
be incomplete. Therefore the result could contain garbage. If
pass-by-reference were used, this garbage would be returned as the actual
parameter. Therefore, since LRM 6.2(12) prohibits returning garbage as the
actual parameter, pass-by-copy must be used. However LRM section 5.2(3) states
that both sides of an assignment statement must be evaluated before the actual
assignment takes place. This would seems to preclude an exception occurring
during the actual assignment. 
     It seems to me that the LRM went to great lengths to make
pass-by-reference a legal implementation, for parameters of mode "out" or "in
out", which are array or record types. However this facility is not being used
by many compiler vendors. 


                                          David Brookman
                                          Magnavox Electronic Systems Company
                                          1313 Production Road
                                          Fort Wayne, IN 46808
                                          November 14, 1988

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Parameter modes
  1988-11-15 13:05 Parameter modes Dale Gaumer
@ 1988-11-18 14:06 ` Robert Firth
  1988-11-21 23:46 ` Michael Murphy
  1 sibling, 0 replies; 8+ messages in thread
From: Robert Firth @ 1988-11-18 14:06 UTC (permalink / raw)


In article <8811151407.AA10227@ajpo.sei.cmu.edu> CONTR22@NOSC-TECR.ARPA (Dale Gaumer) writes:

>     I would like to explore the possibility of using pass-by-reference for
>non-scalar parameters with mode "out" or "in out".
...
>     It seems to me that the LRM went to great lengths to make
>pass-by-reference a legal implementation, for parameters of mode "out" or "in
>out", which are array or record types.

I can confirm, for what it's worth, that it was the conscious intent of
the language designers to permit non-scalar (and non-access) parameters
to be passed by either copy or reference, at the option of the implementor.

If there is anything currently in the RM that prohibits that, I'm not aware
of it; should you know of any such statement, please bring it to the
attention of the Ada Board, so that they can fix it.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Parameter modes
  1988-11-15 13:05 Parameter modes Dale Gaumer
  1988-11-18 14:06 ` Robert Firth
@ 1988-11-21 23:46 ` Michael Murphy
  1 sibling, 0 replies; 8+ messages in thread
From: Michael Murphy @ 1988-11-21 23:46 UTC (permalink / raw)


I'm rather baffled by what you are saying.  The LRM does indeed allow you
to pass parameters by reference, and in fact I know of some (validated) 
compilers that do.  For example, all Verdix-based compilers can pass
parameters by reference.  I suspect that you have simply heard some lame
excuses from some compiler vendors who didn't go to the trouble of
implementing pass-by-reference (perhaps I'm being too harsh here,
but if so then can someone post an example that shows why you cannot
use pass-by-reference?).

-- michael murphy
-- UUCP: {uunet|sun}!elxsi!elk!murphy
-- AT&T: 408-942-0900

^ permalink raw reply	[flat|nested] 8+ messages in thread

* parameter modes
@ 2002-12-25 19:18 Jan
  2002-12-25 20:32 ` Jeffrey Creem
       [not found] ` <d0adua.hs3.ln@beastie.ix.netcom.com>
  0 siblings, 2 replies; 8+ messages in thread
From: Jan @ 2002-12-25 19:18 UTC (permalink / raw)


Hello.

Yet another question/problem:

I know how "in", "out", and "in out" works, so this is not the
problem, but I need to know what exactly happens in memory.
I need to pass a large array, so I need a parameter mode, which
doesn't make a copy of it.

This is what I found out (there is not much about it in the LRM, or
maybe I haven't found the right paragraph):

OUT : a 2nd variable of same type is made, containing undefined
      values. When procedure ends, this new variable is copied to the
      original one (and then the new one is probably removed from
      memory).

So now the question: what happens when using "IN" and "IN OUT"? I can
only guess, so I would be grateful when somebody (who really knows
what's behind it) could explain it to me.

BTW: I know that there can be also "ACCESS" (as a parameter mode),
could someone give an example? Maybe that's what I'm looking for (when
I want to pass an array).


Jan

---
eMail: janp9 @ gmx.net



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: parameter modes
  2002-12-25 19:18 parameter modes Jan
@ 2002-12-25 20:32 ` Jeffrey Creem
  2002-12-26  0:03   ` Stapler
       [not found] ` <d0adua.hs3.ln@beastie.ix.netcom.com>
  1 sibling, 1 reply; 8+ messages in thread
From: Jeffrey Creem @ 2002-12-25 20:32 UTC (permalink / raw)



"Jan" <dontwantspam@abc.com> wrote in message
news:3e09fd53.18465812@news.freenet.de...
> Hello.
>
> Yet another question/problem:
>
> I know how "in", "out", and "in out" works, so this is not the
> problem, but I need to know what exactly happens in memory.
> I need to pass a large array, so I need a parameter mode, which
> doesn't make a copy of it.
>


If you are just worried about run time efficiency then just don't worry
about it. The compiler (any decent compiler (or even some bad ones I have
used)) do the "right" thing with repect to making a copy or not.

The in, out, in out is not like the old pascal "var" mode.

If you really do need to force something specific on a case base case basis
(for some reason other than efficiency) then probably something like access
might be appropriate.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: parameter modes
  2002-12-25 20:32 ` Jeffrey Creem
@ 2002-12-26  0:03   ` Stapler
  2002-12-26  0:09     ` Larry Kilgallen
  0 siblings, 1 reply; 8+ messages in thread
From: Stapler @ 2002-12-26  0:03 UTC (permalink / raw)


On Wed, 25 Dec 2002 15:32:57 -0500, Jeffrey Creem wrote:


> If you are just worried about run time efficiency then just don't worry
> about it. The compiler (any decent compiler (or even some bad ones I
> have used)) do the "right" thing with repect to making a copy or not.
> 
> The in, out, in out is not like the old pascal "var" mode.
> 
> If you really do need to force something specific on a case base case
> basis (for some reason other than efficiency) then probably something
> like access might be appropriate.
 

Do you know if it's possible within the Ada language to define an optional
compiler instruction or pragma that says something like this ...

	if memory_region < X_number_of_bytes then

		Pass_by_copy(memory_region, Destination);

	else

		Pass_by_access_type(memory_region);

	end if;


Just curious.

Stapler



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: parameter modes
  2002-12-26  0:03   ` Stapler
@ 2002-12-26  0:09     ` Larry Kilgallen
  0 siblings, 0 replies; 8+ messages in thread
From: Larry Kilgallen @ 2002-12-26  0:09 UTC (permalink / raw)


In article <wHrO9.459852$P31.154990@rwcrnsc53>, Stapler <spam.magnet@yahoo.com> writes:

> 
> Do you know if it's possible within the Ada language to define an optional
> compiler instruction or pragma that says something like this ...
> 
> 	if memory_region < X_number_of_bytes then
> 
> 		Pass_by_copy(memory_region, Destination);
> 
> 	else
> 
> 		Pass_by_access_type(memory_region);
> 
> 	end if;

You should count on your compiler to do something like that in places
where it is legal and appropriate.  If your compiler does not, perhaps
a compiler you buy in the future will do so.  Trying to work around
the decisions a compiler makes can be painful for you in the future.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: parameter modes
       [not found] ` <d0adua.hs3.ln@beastie.ix.netcom.com>
@ 2002-12-26 15:10   ` Jan
  0 siblings, 0 replies; 8+ messages in thread
From: Jan @ 2002-12-26 15:10 UTC (permalink / raw)


On Wed, 25 Dec 2002 14:03:56 -0800, Dennis Lee Bieber
<wlfraed@ix.netcom.com> wrote:

>freely used on both sides of an assignment. No specification is made on 
>whether IN OUT uses by-reference or value-return (by-copy in each 
>direction); it is perfectly valid for an implementation to copy the 
>value to a local (stack) location, use that copy internally, and then 
>copy the last value back to the original variable on return from the 
>procedure.

This is what I wanted to hear, thanks.

Jan

---
eMail: janp9 @ gmx.net



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2002-12-26 15:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-25 19:18 parameter modes Jan
2002-12-25 20:32 ` Jeffrey Creem
2002-12-26  0:03   ` Stapler
2002-12-26  0:09     ` Larry Kilgallen
     [not found] ` <d0adua.hs3.ln@beastie.ix.netcom.com>
2002-12-26 15:10   ` Jan
  -- strict thread matches above, loose matches on Subject: below --
1988-11-15 13:05 Parameter modes Dale Gaumer
1988-11-18 14:06 ` Robert Firth
1988-11-21 23:46 ` Michael Murphy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox