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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,64ced24a7e89252e X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!not-for-mail From: cjkywt@hotmail.com (Sergey) Newsgroups: comp.lang.ada Subject: Re: Unchecked deallocation question Date: 26 Nov 2004 10:20:01 -0800 Organization: http://groups.google.com Message-ID: References: <41A4AAFF.5060407@mailinator.com> <4540106.PdnsrBBvo5@linux1.krischik.com> <41a66926$0$25070$ba620e4c@news.skynet.be> NNTP-Posting-Host: 81.25.172.4 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1101493201 9864 127.0.0.1 (26 Nov 2004 18:20:01 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 26 Nov 2004 18:20:01 +0000 (UTC) Xref: g2news1.google.com comp.lang.ada:6517 Date: 2004-11-26T10:20:01-08:00 List-Id: "Dmitry A. Kazakov" wrote in message news:... > On Fri, 26 Nov 2004 00:24:15 +0100, Adrien Plisson wrote: > > > Martin Krischik wrote: > >> You should carefully thing if you really need it. Unlike C/C++ the following > >> is actually valid: > >> > >> declare > >> It : Root'Class := Derived'(...); > >> begin > >> ... > >> end; > > > > mmmm, i don't think there is any problem doing this in C++: > > > > class Root; > > class Derived : public Root; > > > > Root &It = Derived( ... ); > > > > it just uses a reference type which is almost the same as ada access > > type but you cannot assign null to it and cannot dereference it. > > Right, the difference appears when Derived is created by a factory: > > declare > It : Root'Class := Create (...); > begin > > Here Create returns Root'Class, so the actual type is unknown until > run-time. In C++ this is only possible using heap and pointers. In Ada It > will be indeed allocated on the stack. Nyet! You're wrong here. The example posted by Adrien is perfectly right. const Root &It = Derived( ... ); Derived gets allocated from the stack... But what you'll do with constant the constant refence is another story...