From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.szaf.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: =?UTF-8?Q?Re:_How_to_get_Ada_to_=e2=80=9ccross_the_chasm=e2=80=9d?= =?UTF-8?Q?=3f?= Date: Fri, 4 May 2018 22:07:37 +0300 Organization: Tidorum Ltd Message-ID: References: <1c73f159-eae4-4ae7-a348-03964b007197@googlegroups.com> <878t9nemrl.fsf@nightsong.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net FQm/Yk+G2O5uqsTASusUpgHuwtZRiu3SjcU8fA2m3cv9tX2V9E Cancel-Lock: sha1:39f6c6wkcxyhoi/AlubDITpOveU= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 In-Reply-To: Xref: reader02.eternal-september.org comp.lang.ada:51985 Date: 2018-05-04T22:07:37+03:00 List-Id: On 18-05-04 16:30 , Jere wrote: > On Wednesday, April 18, 2018 at 1:02:18 PM UTC-4, Lucretia wrote: >> On Wednesday, 18 April 2018 14:29:30 UTC+1, Jere wrote: >> >>> 1. It favors static allocation over dynamic whenever possible. This is >>> huge for small embedded systems. >> >> So does Ada. >> > > This is an interesting point. I would agree that programmers here at > comp.lang.ada promote avoiding access types whenever possible (Ada access > types are more similar to pointers in the Rust world), but the Ada > language itself doesn't really promote that. The Ada language surely helps avoid access types, as it lets us create local variables of dynanmic size. There may be pointers under the hood for such objects, but not visible access types. > It leaves the implementation of many aspects up to the compiler vendor. Yes, but there are some language features to mitigate that, such as the pragma No_Implicit_Heap_Allocation. > Take, for example, discriminated records with a default discriminant. > The language standard doesn't direct how to implement that. True. > GNAT uses static allocation Not universally, I think. AIUI, GNAT uses static allocation (of the size of the largest variant) if the object is on the library level; stack allocation for a local variable (possibly secondary stack); and (of course) heap allocation if the object is dynamically allocated. > and throws an exception if you try to use a discriminant with very > large range to create an array within the struct. Only if the (largest variant of the) object would exceed the memory available in the area where it is created. > If I understand Randy's posts from other email chains, > in Janus it can use the heap to allocate the array. Yes, so I too believe. > The secondary stack is another example. That is not even a standard concept in Ada, but an implementation concept. > Ada's bounded containers are another example. As far as I can see > in the standard, they don't require the use of static allocation > and can be heap implemented by the vendor. Yes, although IMO only an insane cross-compiler for bare metal would use heap allocation for such objects (except, perhaps, when at library level). Unfortunately, I believe that pragma No_Implicit_Heap_Allocation would not warn about such insanity (because, if the program uses a bounded container, that use is explicit, not implicit). This could be an improvement of that pragma in some future Ada. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .