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-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!aioe.org!siG8trSPtxwtkBCOZpBn8A.user.46.165.242.91.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: What is X'Address of an empty array? Date: Wed, 1 Jun 2022 14:49:25 +0200 Organization: Aioe.org NNTP Server Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: gioia.aioe.org; logging-data="52567"; posting-host="siG8trSPtxwtkBCOZpBn8A.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org"; User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 X-Notice: Filtered by postfilter v. 0.9.2 Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:63902 List-Id: On 2022-05-31 23:35, Randy Brukardt wrote: > Aliased objects should never have zero-size in Ada (or, at least, ever be > allocated at the same address). I believe that is because of the required > result of the equality operator. Specifically: > > type NUL is array (1..0) of Integer; > A, B : aliased NUL; > type PNul is access Nul; > PA : PNul := A'Access; PB : PNul := B'Access; > > if PA = PB then > Report.Failed ("Access to two distinct objects can not be equal"); > end if; > > If an object is not aliased, it is undefined whether 'Address will work > reliably with it (it probably does in GNAT, it might not in Janus/Ada, etc.) > If the objects ARE aliased, then 'Address works essentially the same as > 'Access. > > I personally find this a bit of overspecification in Ada, but since > zero-size objects are unusual, no one has thought it worth going through the > effort to change. (And of course such a change would complicate static > analysis.) We (the ARG) did discuss this topic at one point (I don't have > the AI number at hand). It is actually rather nice. I recently stumbled upon code: A (A'First)'Address in C bindings, when the other side has something like: const double * a, int len It of course fails in the marginal case when the array is empty. But A'Address seems never do. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de