comp.lang.ada
 help / color / mirror / Atom feed
From: mfeldman@seas.gwu.edu (Michael Feldman)
Subject: Reference vs. copy semantics in passing parameters
Date: 17 Feb 91 00:19:22 GMT	[thread overview]
Message-ID: <2742@sparko.gwu.edu> (raw)
In-Reply-To: jls.666659373@yoda

In article <jls.666659373@yoda> jls@yoda.Rational.COM (Jim Showalter) writes:
>There is an unsafe aspect of passing access types as IN parameters in Ada
>that is, sad to say, handled rather better in C++.
>
>In Ada, you can pass an access type to a function as an IN:
>	type Some_Foo...
>        type Pointer is access Some_Foo;
>        function Some_Bar (Some_Param : in Pointer)...
>And then, inside the function, dereference the pointer and modify the
>pointed-to construct.
>
>In C++, you can declare not only the pointer constant but the pointed
>to construct constant as well. This allows passing by reference in a
>read-only manner, which is NOT possible in Ada at present.

Well now I'm curious. Given that only scalars and small structures are
usually passed by copy, why would you want to guarantee reference
passing for read-only parameters in such a kludgy way? Ada provides you
with everything you need:

- parameters large enough to cause performance concerns are passed by
  reference anyway (in any reasonable implementation, anyway);

- IN parameters are read-only, no matter how they are passed.

Am I missing some important other issue here? What aren't you getting
from this combination of features?

Mike Feldman

PS: It seems to me that Ada9x could clarify the issue by simply requiring
that structured parameters be passed by reference (instead of the Ada83
rule that it's implementation-dependent). Since a program whose behavior
depends upon the method of passing is - by definition of the LRM -
erroneous, the only programs that would break would be erroneous ones,
which Ada9x says it doesn't care about. So the clarification would be
upward compatible. Ada9x-ers: what would be the objections?

  reply	other threads:[~1991-02-17  0:19 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1991-02-11 15:06 ADA Compiling Query Gordon Russell
1991-02-12 19:01 ` Michael Feldman
1991-02-13 21:16 ` Jeff Bartlett
1991-02-14 16:45   ` Michael Feldman
1991-02-15 23:09     ` Jim Showalter
1991-02-17  0:19       ` Michael Feldman [this message]
1991-02-17 18:54         ` Reference vs. copy semantics in passing parameters Erland Sommarskog
1991-02-18 18:41           ` Doug Smith
1991-02-18  0:36         ` Jim Showalter
1991-02-18  1:42           ` Michael Feldman
1991-02-18 18:49           ` Arthur Evans
1991-02-19  2:05             ` Michael Feldman
1991-02-18 13:10         ` madmats
1991-02-19 19:00           ` Robert I. Eachus
1991-05-16 13:51         ` Alex Blakemore
1991-05-17  8:19           ` Matthias Ulrich Neeracher
1991-05-17 13:44           ` Markku Sakkinen
1991-05-28  5:28           ` Kenneth Almquist
1991-02-18 14:33 ` ADA Compiling Query stt
replies disabled

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