comp.lang.ada
 help / color / mirror / Atom feed
From: mfeldman@seas.gwu.edu (Michael Feldman)
Subject: Re: ADA Compiling Query
Date: 14 Feb 91 16:45:36 GMT	[thread overview]
Message-ID: <2725@sparko.gwu.edu> (raw)
In-Reply-To: 1991Feb13.211643.25777@rti.rti.org

In article <1991Feb13.211643.25777@rti.rti.org> jb@rti.rti.org (Jeff Bartlett) writes:
>In article <5572@baird.cs.strath.ac.uk>, gor@cs.strath.ac.uk (Gordon Russell) writes:
>
>See ANSI/MIL-STD-1815A section 6.2 paragraph 7:
>
>    .... The language does not define which of these two mechanisms is to
>    be adopted for parameter passing, nor whether different calls to the
>    same subprogram are to use the same mechanism.   The execution of a
>    program is erroneous if its effect depends on which mechanism is
>    selected by the implementation.
>
C'mon, guys - a little precision please. This applies only to _structured_
parameters. The preceding paragraph (6) states clearly that _scalars_ are
copied.

I've bumped into a lot of Pascal folks learning Ada who think that passing
an array as IN OUT will magically get it passed by reference. This is a
trick used in Pascal - you pass an array as VAR even if it is being used
as an input parameter, because the _Pascal_ standard requires that it be
copied otherwise. This sticks you in a bind in Pascal, because you've
turned an input parameter into something your procedure may inadvertently
modify. So you've traded speed for reliability. Too bad, but this is
what Prof. Wirth wanted. (It's carried over to Modula-2 also).

Carrying the Pascal trick over to Ada is futile and unnecessary. An IN
parameter _cannot_ be modified; the compiler won't allow it. This permits
the implementer to pass an array (yes, even as an IN parameter) by reference
to save copying time and space. As I said in a previous posting, most
implementers will pass by reference any structure large enough to be of
concern. But if you think that using the Pascal trick - artificially making
the array IN OUT to _guarantee_ that it'll be passed by reference - will
work, guess again.

Mike Feldman

  reply	other threads:[~1991-02-14 16:45 UTC|newest]

Thread overview: 20+ 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 [this message]
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
1991-05-17 13:44           ` Markku Sakkinen
1991-05-28  5:28           ` Kenneth Almquist
1991-02-18 14:33 ` ADA Compiling Query stt
     [not found] <5572@baird.cs.strath.ac.uk#  <20600085@inmet>
1991-02-21 20:40 ` Michael Feldman
replies disabled

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