comp.lang.ada
 help / color / mirror / Atom feed
From: "zork" <zork@nospam.com>
Subject: Re: "out" and  "in out"
Date: Thu, 29 Jul 2004 00:07:48 +1000
Date: 2004-07-29T00:07:48+10:00	[thread overview]
Message-ID: <4107b35c@dnews.tpgi.com.au> (raw)
In-Reply-To: opsbq1zzd0p4pfvb@bram-2

Thanks for the response everyone. I need to be careful in my implementation.
Some things are obviously not obvious :)

cheers
zork


"Nick Roberts" <nick.roberts@acm.org> wrote in message
news:opsbq1zzd0p4pfvb@bram-2...
> 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





  reply	other threads:[~2004-07-28 14:07 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
2004-07-28 14:07   ` zork [this message]
  -- 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