From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-0.5 required=3.0 tests=BAYES_05,FORGED_GMAIL_RCVD, FREEMAIL_FROM,NICE_REPLY_A autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: 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 Message-ID: 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 Xref: reader02.eternal-september.org comp.lang.ada:63117 List-Id: 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.