Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

If Machiavelli were a programmer, he'd have worked for AT&T.


devel / comp.lang.ada / Did I find a (nearly-)gotcha here?

SubjectAuthor
* Did I find a (nearly-)gotcha here?reinert
+- Re: Did I find a (nearly-)gotcha here?Niklas Holsti
`* Re: Did I find a (nearly-)gotcha here?Rod Kay
 `- Re: Did I find a (nearly-)gotcha here?G.B.

1
Did I find a (nearly-)gotcha here?

<29091147-1b81-4a3b-a646-c6a6d1ebe4ean@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:ac8:570b:: with SMTP id 11mr23360098qtw.128.1636789569895;
Fri, 12 Nov 2021 23:46:09 -0800 (PST)
X-Received: by 2002:a5b:f50:: with SMTP id y16mr23675309ybr.159.1636789569762;
Fri, 12 Nov 2021 23:46:09 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!4.us.feeder.erje.net!2.eu.feeder.erje.net!feeder.erje.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Fri, 12 Nov 2021 23:46:09 -0800 (PST)
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: <29091147-1b81-4a3b-a646-c6a6d1ebe4ean@googlegroups.com>
Subject: Did I find a (nearly-)gotcha here?
From: rein...@gmail.com (reinert)
Injection-Date: Sat, 13 Nov 2021 07:46:09 +0000
Content-Type: text/plain; charset="UTF-8"
 by: reinert - Sat, 13 Nov 2021 07:46 UTC

Hello,

Assume the following program:

with Text_Io; use Text_Io;
procedure test2 is
procedure test_a(ok : out Boolean) is
begin
if false then
ok := true;
end if;
end test_a;
procedure test_b(ok : in out Boolean) is
begin
if false then
ok := true;
end if;
end test_b;
ok_a,ok_b : Boolean := true;
begin
test_a(ok_a);
test_b(ok_b);
Put_Line("ok_a = " & ok_a'Image);
Put_Line("ok_b = " & ok_b'Image);
end test2;

I get the following output (using GNAT Community Edition):

ok_a = FALSE
ok_b = TRUE

As far as I understand, this is correct.
However, I think I remember that (some) older versions of the GNAT compiler gave a different result. Could others try? And does my program example reveal an unnecessary gotcha?

reinert

Re: Did I find a (nearly-)gotcha here?

<iv9cmaFecccU1@mid.individual.net>

 copy mid

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

 copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: niklas.h...@tidorum.invalid (Niklas Holsti)
Newsgroups: comp.lang.ada
Subject: Re: Did I find a (nearly-)gotcha here?
Date: Sat, 13 Nov 2021 10:52:26 +0200
Organization: Tidorum Ltd
Lines: 61
Message-ID: <iv9cmaFecccU1@mid.individual.net>
References: <29091147-1b81-4a3b-a646-c6a6d1ebe4ean@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net wQis+EHXpcciBjSvJELfdQ/XvtCgKveZEH+tiv3DLwlfMElf2s
Cancel-Lock: sha1:EVjW0uJMl1xyAhWt0ycXmz7dWBY=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0)
Gecko/20100101 Thunderbird/78.14.0
In-Reply-To: <29091147-1b81-4a3b-a646-c6a6d1ebe4ean@googlegroups.com>
Content-Language: en-US
 by: Niklas Holsti - Sat, 13 Nov 2021 08:52 UTC

On 2021-11-13 9:46, reinert wrote:
> Hello,
>
> Assume the following program:
>
> with Text_Io; use Text_Io;
> procedure test2 is
> procedure test_a(ok : out Boolean) is
> begin
> if false then
> ok := true;
> end if;
> end test_a;
> procedure test_b(ok : in out Boolean) is
> begin
> if false then
> ok := true;
> end if;
> end test_b;
> ok_a,ok_b : Boolean := true;
> begin
> test_a(ok_a);
> test_b(ok_b);
> Put_Line("ok_a = " & ok_a'Image);
> Put_Line("ok_b = " & ok_b'Image);
> end test2;
>
> I get the following output (using GNAT Community Edition):
>
> ok_a = FALSE
> ok_b = TRUE
>
> As far as I understand, this is correct.

The value of ok_b is correct.

The value of ok_a is not defined by the language, I believe. The
parameter test_a.ok is passed by copy-out (but not copy-in), and is not
assigned a value in test_a, therefore the returned value comes from an
uninitialized local Boolean, and is undefined.

> However, I think I remember that (some) older versions of the GNAT
> compiler gave a different result.

That may be so, but it would not be bug in GNAT. It is a programmer error.

> And does my program example reveal an unnecessary gotcha?

The gotcha is that Ada and GNAT do not detect all uses of uninitialized
variables. That is regrettable, but it would be very expensive to detect
them.

Note that if the "out" parameter has a constrained subtype, say Integer
range 1 .. 10, and is not assigned a value in the subprogram, a
Constraint_Error may be raised on return if the uninitialized value
fails the subtype check in the copy-out. (This has happened to me, when
I was younger and perhaps less learned.)

Re: Did I find a (nearly-)gotcha here?

<smnuf8$s9h$1@dont-email.me>

 copy mid

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

 copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: rodak...@gmail.com (Rod Kay)
Newsgroups: comp.lang.ada
Subject: Re: Did I find a (nearly-)gotcha here?
Date: Sat, 13 Nov 2021 19:53:57 +1100
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <smnuf8$s9h$1@dont-email.me>
References: <29091147-1b81-4a3b-a646-c6a6d1ebe4ean@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 13 Nov 2021 08:54:00 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="a2d1a6d5065b31d0de62bb10b5ac60ab";
logging-data="28977"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/NUkywCaN5/B1BU8Z889rJ+JPlfoWxSqk="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.3.0
Cancel-Lock: sha1:Cq8dkyjpCy7GnGw2opkhdOBFrzk=
In-Reply-To: <29091147-1b81-4a3b-a646-c6a6d1ebe4ean@googlegroups.com>
Content-Language: en-US
 by: Rod Kay - Sat, 13 Nov 2021 08:53 UTC

On 13/11/21 18:46, reinert wrote:
>
> procedure test_a(ok : out Boolean) is
> begin
> if false then
> ok := true;
> end if;
> end test_a;
>
> I get the following output (using GNAT Community Edition):
>
> ok_a = FALSE
> ok_b = TRUE
>
> As far as I understand, this is correct.
> However, I think I remember that (some) older versions of the GNAT compiler gave a different result. Could others try? And does my program example reveal an unnecessary gotcha?
>
> reinert
>

Hi reinert,

The value of an 'out' only parameter needs to be explicitly set. The
initial value of the 'ok_a' variable will be discarded and then set to
the value of the 'ok' parameter within 'test_a' when the call completes.
Since 'ok' is not set in 'test_a' it's value is indeterminate (and
therefore erroneous).

I'd expect GNAT to issue a warning. Probably you need to add a flag
to GNAT to enable that warning. Perhaps try adding '-gnatwa'.

Regards.

Re: Did I find a (nearly-)gotcha here?

<smqh6a$e85$1@dont-email.me>

 copy mid

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

 copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bauh...@notmyhomepage.invalid (G.B.)
Newsgroups: comp.lang.ada
Subject: Re: Did I find a (nearly-)gotcha here?
Date: Sun, 14 Nov 2021 09:25:45 +0100
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <smqh6a$e85$1@dont-email.me>
References: <29091147-1b81-4a3b-a646-c6a6d1ebe4ean@googlegroups.com>
<smnuf8$s9h$1@dont-email.me>
Reply-To: nonlegitur@notmyhomepage.de
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 14 Nov 2021 08:25:46 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="3a8f12fdf5f2e9071ff9e353f6241c40";
logging-data="14597"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19lD0lW+4skY9MdCqPKN/ZhVhe8ukGkLDY="
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0)
Gecko/20100101 Thunderbird/91.3.0
Cancel-Lock: sha1:5m4oSSdfmQMj4ChbRRrcJenx60c=
In-Reply-To: <smnuf8$s9h$1@dont-email.me>
Content-Language: en-US
 by: G.B. - Sun, 14 Nov 2021 08:25 UTC

On 13.11.21 09:53, Rod Kay wrote:
> On 13/11/21 18:46, reinert wrote:
>>
>>     procedure test_a(ok :    out Boolean) is
>>     begin
>>        if false then
>>           ok := true;
>>        end if;
>>     end test_a;
>>
>> However, I think I remember that (some) older versions of the GNAT compiler gave a different result. Could others try?  And does my program example reveal an unnecessary gotcha?
>>
>    I'd expect GNAT to issue a warning. Probably you need to add a flag to GNAT to enable that warning. Perhaps try adding '-gnatwa'.

GCC's -Wuninitialized does as Rod Kay says.

1
server_pubkey.txt

rocksolid light 0.9.7
clearnet tor