comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Question on in/out parameters
Date: Mon, 2 May 2022 16:35:29 -0500	[thread overview]
Message-ID: <t4pir2$gje$1@dont-email.me> (raw)
In-Reply-To: 85d12db3-e308-46bc-9be6-20b48ebe4fd2n@googlegroups.com

"reinert" <reinkor@gmail.com> wrote in message 
news:85d12db3-e308-46bc-9be6-20b48ebe4fd2n@googlegroups.com...
>I expected an "out" parameter in a procedure to be like declaring the
>parameter "from scratch" (with actual initial default value). For my
>compiler (GNAT Community Edition, May 2021) it seems like the
>out parameters brings in content from the calling procedure. Should
>it be like this?

It depends on the data type; there is a complex series of rules about what 
is passed in for an out parameter. The basic idea is that stuff like bounds 
and discriminants are passed in, while other things may or may not be passed 
in.

Probably it is best to think of the distinction between in out and out 
parameters as being for the programmer, as noted by Jean-Pierre. When you 
say "out", you are asserting that you do not care what is passed in -- it 
could be in any state or even uninitialized. When you say "in out", you 
expect a value that you can use in the subprogram, so it has to meet the 
constraints and other requirements.

For instance, "out" parameters are checked as little as possible on the way 
in, while an "in out" parameter has all of the checking one might expect. Of 
course, if you are working with a well-designed ADT (as in the case of the 
containers), the difference between an unchecked item and a fully checked 
item is minimal. If you were working with an elementary type like an integer 
or access type, the input value may not be initialized at all.

Hope this helps.

                               Randy.


      parent reply	other threads:[~2022-05-02 21:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-30  8:57 Question on in/out parameters reinert
2022-04-30  9:38 ` Jeffrey R.Carter
2022-04-30 11:30   ` reinert
2022-05-01  7:50     ` J-P. Rosen
2022-05-02 21:35 ` Randy Brukardt [this message]
replies disabled

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