comp.lang.ada
 help / color / mirror / Atom feed
From: neeri@iis.ethz.ch (Matthias Ulrich Neeracher)
Subject: Re: Reference vs. copy semantics in passing parameters
Date: 17 May 91 08:19:29 GMT	[thread overview]
Message-ID: <NEERI.91May17101929@iis.ethz.ch> (raw)
In-Reply-To: blakemor@software.org's message of 16 May 91 13:51:03 GMT

In article <1991May16.135103.1688@software.org> blakemor@software.org (Alex Blakemore) writes:
>In article <2742@sparko.gwu.edu> mfeldman@seas.gwu.edu () writes:
>> In article <jls.666659373@yoda> jls@yoda.Rational.COM (Jim Showalter) writes:
>> 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.
>
>This sounds like a nice safety feature but can callers really rely on it ?
>Even if the C++ language prevents updating the object if the pointer is
>declared appropriately, does it prevent assignment to a normal pointer
>which will allow the referenced object to be updated ?
>[...]
>Consider this Ada flavored example, where constant means the referenced
>object may not be updated.
>
>procedure look_at_object (p : in CONSTANT ptr_to_object);
>
>procedure look_at_object (p : in CONSTANT ptr_to_object) is
>  temp : ptr_to_object;
>begin 
>  temp := p;  -- is this legal in C++ ?
>  p.all := anything;
>end;
>
>Unless C++ prevents the assignment to another pointer above, then the feature
>can be easily subverted (purposely or accidently).

[Sorry to post C++ to comp.lang.ada, but the question is posted here]

In C++, the above assignment is illegal, so the risk of subverting the feature
accidentally is low. On the other hand, the assignment can easily be done if an
explicit type cast to the non-constant type is employed in the right-hand side,
so the feature can indeed easily be subverted purposely.

I tend to agree with this design philosophy, as I believe that it is beneficial
to try to guard programmers from their own stupid... I mean fallibility, but that
there is little use of trying to control their malice with programming language
features. A borderline case is, of course, programmer's lazyness.

Matthias

-----
Matthias Neeracher                                      neeri@iis.ethz.ch
   "These days, though, you have to be pretty technical before you can 
    even aspire to crudeness." -- William Gibson, _Johnny Mnemonic_

  reply	other threads:[~1991-05-17  8: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       ` Reference vs. copy semantics in passing parameters Michael Feldman
1991-02-17 18:54         ` 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 [this message]
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