From: "Nick Roberts" <nick.roberts@acm.org>
Subject: Re: "out" and "in out"
Date: Mon, 26 Jul 2004 15:46:37 +0100
Date: 2004-07-26T15:46:37+01:00 [thread overview]
Message-ID: <opsbq1zzd0p4pfvb@bram-2> (raw)
In-Reply-To: 4104d5de@dnews.tpgi.com.au
On Mon, 26 Jul 2004 19:58:22 +1000, zork <zork@nospam.com> wrote:
> ...
> By chance I created a small program as follows:
>
> ===========
> s : string := "CAT";
>
> procedure modify ( s1 : out string ) is
> begin
> s1(2) := 'U';
> end modify;
>
> ..
>
> put ( modify(s) );
> ===========
>
> now I get as a result "CUT", and i dont understand why i get
> this result.
> Doesnt the "out" specify that its initial value isnt passed
> in via the parameter?
Yes, but it doesn't forbid the compiler to (effectively) pass
the value in. In practice, this is likely to happen if the
parameter is of a composite type (an array or record), because
the compiler will probably choose to pass it by reference.
> But it seems to be passed in the above. In fact the "out"
> is acting like an "in out".
Yes. This is permitted. But your program would be wrong to
rely upon it.
If you were to try:
===========
n : integer := 456;
procedure modify ( n1 : out integer ) is
begin
n1 := n1+44;
end modify;
...
modify(n);
put(n);
===========
I think you might not get 500 printed out (I don't, running
this on GNAT 3.15p on Win XP (and GNAT gives a warning)).
--
Nick Roberts
next prev parent reply other threads:[~2004-07-26 14:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-07-26 9:58 "out" and "in out" zork
2004-07-26 11:00 ` David C. Hoos
2004-07-26 11:30 ` Martin Krischik
2004-07-26 14:46 ` Nick Roberts [this message]
2004-07-28 14:07 ` zork
-- strict thread matches above, loose matches on Subject: below --
2004-07-26 10:54 Christoph Karl Walter Grein
2004-07-26 14:16 ` Marc A. Criley
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox