Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

grep me no patterns and I'll tell you no lines.


devel / comp.lang.ada / Re: Question on in/out parameters

SubjectAuthor
* Question on in/out parametersreinert
+* Re: Question on in/out parametersJeffrey R.Carter
|`* Re: Question on in/out parametersreinert
| `- Re: Question on in/out parametersJ-P. Rosen
`- Re: Question on in/out parametersRandy Brukardt

1
Question on in/out parameters

<85d12db3-e308-46bc-9be6-20b48ebe4fd2n@googlegroups.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=6871&group=comp.lang.ada#6871

 copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:622a:1750:b0:2f3:6453:b382 with SMTP id l16-20020a05622a175000b002f36453b382mr2689241qtk.396.1651309057397;
Sat, 30 Apr 2022 01:57:37 -0700 (PDT)
X-Received: by 2002:a0d:ffc3:0:b0:2eb:2327:3361 with SMTP id
p186-20020a0dffc3000000b002eb23273361mr3175570ywf.36.1651309057241; Sat, 30
Apr 2022 01:57:37 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Sat, 30 Apr 2022 01:57:37 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=84.209.88.37; posting-account=bPTmZAoAAAC_6HP9XLKB9aAAxBa6BuOR
NNTP-Posting-Host: 84.209.88.37
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <85d12db3-e308-46bc-9be6-20b48ebe4fd2n@googlegroups.com>
Subject: Question on in/out parameters
From: rein...@gmail.com (reinert)
Injection-Date: Sat, 30 Apr 2022 08:57:37 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 58
 by: reinert - Sat, 30 Apr 2022 08:57 UTC

Hello,

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?

Below is a test program to illustrate.

reinert

with Ada.Containers; use Ada.Containers;
with Ada.Containers.Vectors;
with Ada.Text_IO; use Ada.Text_IO;
procedure test2 is

package Integer_Vectors is new Ada.Containers.Vectors
(Index_Type => Natural, Element_Type => Integer);
use Integer_Vectors;

V : Vector := 10 & 20;

procedure rk_in_out(W : in out Vector) is
begin
W.Append(30); W.Append(40);
end rk_in_out;

procedure rk_out(W : out Vector) is
begin
W.Clear; -- I expected this statement to be redundant since W is "out parameter" (try to remove it and see if results remain the same.)?
W.Append(30); W.Append(40);
end rk_out;

begin

New_Line;
Put ("First V : ");
for e of V loop
Put(e'Image & " ");
end loop;

rk_in_out(W => V);
New_Line;
Put ("Second V : ");
for e of V loop
Put(e'Image & " ");
end loop;

rk_out(W => V);
New_Line;
Put ("Third V : ");
for e of V loop
Put(e'Image & " ");
end loop;

end test2;

Re: Question on in/out parameters

<t4j01u$djo$1@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=6872&group=comp.lang.ada#6872

 copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: spam.jrc...@spam.acm.org.not (Jeffrey R.Carter)
Newsgroups: comp.lang.ada
Subject: Re: Question on in/out parameters
Date: Sat, 30 Apr 2022 11:38:06 +0200
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <t4j01u$djo$1@dont-email.me>
References: <85d12db3-e308-46bc-9be6-20b48ebe4fd2n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 30 Apr 2022 09:38:06 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="aeef42cce4c4d709da74e3fa66e7b2aa";
logging-data="13944"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/S4dH5g3oAws/TSnnS2RdUWexRajS4CYA="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.8.1
Cancel-Lock: sha1:ulvfsIOa/jFeldOy18hOt2j5TCU=
In-Reply-To: <85d12db3-e308-46bc-9be6-20b48ebe4fd2n@googlegroups.com>
Content-Language: en-US
 by: Jeffrey R.Carter - Sat, 30 Apr 2022 09:38 UTC

On 2022-04-30 10:57, reinert wrote:
>
> 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?

Parameters in Ada are either passed by copy or passed by reference, regardless
of parameter mode. The rules are

* Scalar types are always passed by copy
* Tagged types are always passed by reference
* Limited types are always passed by reference
* All other types are decided by the compiler

For the types that are passed by reference, "in out" and "out" mode are identical.

Vector is a tagged type, so this applies to it.

One can argue that an out-mode parameter of a by-reference type should be
"reinitialized" before use, but the Ada-9X revision decided not to require this.

--
Jeff Carter
"Hello! Smelly English K...niggets."
Monty Python & the Holy Grail
08

Re: Question on in/out parameters

<fb8e503f-70a3-44a3-867e-132191f25762n@googlegroups.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=6873&group=comp.lang.ada#6873

 copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a37:c44:0:b0:69f:81cb:1d6a with SMTP id 65-20020a370c44000000b0069f81cb1d6amr2378579qkm.494.1651318215095;
Sat, 30 Apr 2022 04:30:15 -0700 (PDT)
X-Received: by 2002:a25:e90a:0:b0:648:a3da:b52b with SMTP id
n10-20020a25e90a000000b00648a3dab52bmr3272468ybd.100.1651318214913; Sat, 30
Apr 2022 04:30:14 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Sat, 30 Apr 2022 04:30:14 -0700 (PDT)
In-Reply-To: <t4j01u$djo$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=84.209.88.37; posting-account=bPTmZAoAAAC_6HP9XLKB9aAAxBa6BuOR
NNTP-Posting-Host: 84.209.88.37
References: <85d12db3-e308-46bc-9be6-20b48ebe4fd2n@googlegroups.com> <t4j01u$djo$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <fb8e503f-70a3-44a3-867e-132191f25762n@googlegroups.com>
Subject: Re: Question on in/out parameters
From: rein...@gmail.com (reinert)
Injection-Date: Sat, 30 Apr 2022 11:30:15 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 39
 by: reinert - Sat, 30 Apr 2022 11:30 UTC

Thanks for sorting out my confusion.

So there is no difference between "in", "in out" and "out" for Vectors except that the compiler protests if I try to change an "in parameter" in the actual subroutine/function?

reinert

lørdag 30. april 2022 kl. 11:38:08 UTC+2 skrev Jeffrey R.Carter:
> On 2022-04-30 10:57, reinert wrote:
> >
> > 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?
> Parameters in Ada are either passed by copy or passed by reference, regardless
> of parameter mode. The rules are
>
> * Scalar types are always passed by copy
> * Tagged types are always passed by reference
> * Limited types are always passed by reference
> * All other types are decided by the compiler
>
> For the types that are passed by reference, "in out" and "out" mode are identical.
>
> Vector is a tagged type, so this applies to it.
>
> One can argue that an out-mode parameter of a by-reference type should be
> "reinitialized" before use, but the Ada-9X revision decided not to require this.
>
> --
> Jeff Carter
> "Hello! Smelly English K...niggets."
> Monty Python & the Holy Grail
> 08

Re: Question on in/out parameters

<t4le38$t8j$1@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=6879&group=comp.lang.ada#6879

 copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ros...@adalog.fr (J-P. Rosen)
Newsgroups: comp.lang.ada
Subject: Re: Question on in/out parameters
Date: Sun, 1 May 2022 09:50:03 +0200
Organization: Adalog
Lines: 20
Message-ID: <t4le38$t8j$1@dont-email.me>
References: <85d12db3-e308-46bc-9be6-20b48ebe4fd2n@googlegroups.com>
<t4j01u$djo$1@dont-email.me>
<fb8e503f-70a3-44a3-867e-132191f25762n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 1 May 2022 07:50:00 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="a28b021dfb314ca4d6d6594a5c468529";
logging-data="29971"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Niyg7ggV067ML0wvDzTr1"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.8.1
Cancel-Lock: sha1:N3RkwHmwfSFN6ECxM5ZB9peJg0g=
In-Reply-To: <fb8e503f-70a3-44a3-867e-132191f25762n@googlegroups.com>
Content-Language: fr
 by: J-P. Rosen - Sun, 1 May 2022 07:50 UTC

Le 30/04/2022 à 13:30, reinert a écrit :
> So there is no difference between "in", "in out" and "out" for
> Vectors except that the compiler protests if I try to change an "in
> parameter" in the actual subroutine/function?
>
"in" is read only, so there is a difference.

The difference between "in out" and "out" is not for the compiler (in
this case), but for the reader: if you declare a parameter as "out", you
promise that you won't use the previous value of the parameter, and
therefore that the procedure is OK if you call it with an uninitialized
variable (i.e. that the procedure is appropriate to initialize an
otherwise uninitialized variable).

--
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52
https://www.adalog.fr

Re: Question on in/out parameters

<t4pir2$gje$1@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=6883&group=comp.lang.ada#6883

 copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ran...@rrsoftware.com (Randy Brukardt)
Newsgroups: comp.lang.ada
Subject: Re: Question on in/out parameters
Date: Mon, 2 May 2022 16:35:29 -0500
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <t4pir2$gje$1@dont-email.me>
References: <85d12db3-e308-46bc-9be6-20b48ebe4fd2n@googlegroups.com>
Injection-Date: Mon, 2 May 2022 21:35:30 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="dffbaacecbf208fb9cb9f079fd8667ba";
logging-data="17006"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19fPJpID/+fEvnr2s13k4P662drSwoiObc="
Cancel-Lock: sha1:rDTdsvNP4K5lpKhqyI9jTJUxgPo=
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246
X-RFC2646: Format=Flowed; Original
X-Newsreader: Microsoft Outlook Express 6.00.2900.5931
X-Priority: 3
X-MSMail-Priority: Normal
 by: Randy Brukardt - Mon, 2 May 2022 21:35 UTC

"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.

1
server_pubkey.txt

rocksolid light 0.9.7
clearnet tor