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=-2.2 required=3.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM,NICE_REPLY_A,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Rod Kay Newsgroups: comp.lang.ada Subject: Re: Is this a compiler bug ? Date: Mon, 20 Mar 2023 13:24:40 +1100 Organization: A noiseless patient Spider Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Mon, 20 Mar 2023 02:24:42 -0000 (UTC) Injection-Info: reader01.eternal-september.org; posting-host="7b118bbe60abd8dc27d15111e7b55641"; logging-data="3433244"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+M4b2uBsxmcz1WutB82TGZm32loMxO6Gs=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Cancel-Lock: sha1:QF6CpgkW0AXW3UsQDv9t1Q/851g= In-Reply-To: Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:65006 List-Id: On 19/3/23 21:33, Jeffrey R.Carter wrote: > On 2023-03-19 07:17, Rod Kay wrote: >> >>     In the 'to_Stack' function, the Capacity is reserved correctly but >> in the test program when the stack is created and assigned to a >> variable, the capacity is 0. > > I think this is acceptable behavior. See ARM A.18.2 (147.19/3, 147.20/3, > & 147.b/3) > (http://www.ada-auth.org/standards/aarm12_w_tc1/html/AA-A-18-2.html). > The first two sections define the behavior of procedure Assign, while > the last states "Assign(A, B) and A := B behave identically". > > Assign (A, B) only changes the capacity of A if A.Capacity < B.Length. > > So if the compiler does not use build-in-place for the initialization of > the variable, then the assignment of the function result should not > change the capacity of the variable from its (apparent) default of zero > (there is, of course, no requirement for the capacity of a > default-initialized vector). > > The discussion of capacities for vectors is only meaningful for a subset > of possible implementations, so messing with capacities may have no > meaningful effect at all. > > For an unbounded stack based on a linked list (with no concept of > capacity) you could use > PragmARC.Data_Structures.Stacks.Unbounded.Unprotected > (https://github.com/jrcarter/PragmARC/blob/Ada-12/pragmarc-data_structures-stacks-unbounded-unprotected.ads). > Thank you, Jeffrey, for the detailed reply. I'm now using a limited record with an extended return for 'build-in-place' initialisation and am getting the behavior I desired. Cheers.