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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 2002:a05:620a:557:: with SMTP id o23mr6904091qko.337.1585954122430; Fri, 03 Apr 2020 15:48:42 -0700 (PDT) X-Received: by 2002:aca:62d5:: with SMTP id w204mr4684008oib.119.1585954122034; Fri, 03 Apr 2020 15:48:42 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!aioe.org!peer03.am4!peer.am4.highwinds-media.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 3 Apr 2020 15:48:41 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: google-groups.googlegroups.com; posting-host=2a02:c7d:897d:6600:4d20:94e7:f3d2:5dc0; posting-account=YRfoYAoAAADhSEO2nLYx10QUUvp8akYl NNTP-Posting-Host: 2a02:c7d:897d:6600:4d20:94e7:f3d2:5dc0 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <94a54092-a56f-4a99-aaec-08dd611c8fd8@googlegroups.com> Subject: Proposal: Auto-allocation of Indefinite Objects From: Stephen Davies Injection-Date: Fri, 03 Apr 2020 22:48:42 +0000 Content-Type: text/plain; charset="UTF-8" X-Received-Bytes: 2835 X-Received-Body-CRC: 571144200 Xref: reader01.eternal-september.org comp.lang.ada:58304 Date: 2020-04-03T15:48:41-07:00 List-Id: Firstly, apologies if this has already been discussed or, more likely, if it's a really stupid idea for some reason that I haven't thought of. My proposal is that it should (sometimes?) be possible to declare objects of indefinite types such as String and have the compiler automatically declare the space for them without the programmer having to resort to access types. Benefits: 1. Easier, especially for newbies/students. 2. Safer due to reduced use of access types. 3. Remove the need to have definite and indefinite verions of generic units. It is the 3rd reason that initially got me thinking about this. It seems excessive to have two versions of packages just because one version can say "Node.Item := New_Item;" but the other has to say "Node.Item_Ptr := new Element_Type'(New_Item);". It's probably not a good idea for auto-allocation to be the default behaviour, so I suggest something like: type Node_Type is record Item : new Element_Type; Prev : Node_Ptr_Type; Next : Node_Ptr_Type; end record; If Element_Type is a definite type in the instantiation then Node.Item will be a normal object of that type. Otherwise, it is implemented as a pointer but the code still treats it as an object. The target of the pointer is allocated on assignment of the object. The pointer cannot be copied to any other object. Assignments of the whole record will perform a deep-copy of the auto-allocated component. The target of the Node.Item pointer can be auto-deallocated when Node goes out of scope or is deallocated. Ok, I've probably missed something obvious and have been wasting my time, but at least I've got plenty of time to waste at the moment.