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=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!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Unchecked deallocation question Date: Sat, 27 Nov 2004 09:43:54 +0100 Organization: cbb software GmbH Message-ID: <68nv6svhd1vr.1lihv47f1pt7w.dlg@40tude.net> References: <41A4AAFF.5060407@mailinator.com> <4540106.PdnsrBBvo5@linux1.krischik.com> <41a66926$0$25070$ba620e4c@news.skynet.be> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de CleAv7G4KoHpARbTyPhaswmWvZfnDPbvEk5+zVU4uPORZw4Qc= User-Agent: 40tude_Dialog/2.0.12.1 Xref: g2news1.google.com comp.lang.ada:6545 Date: 2004-11-27T09:43:54+01:00 List-Id: On 26 Nov 2004 10:20:01 -0800, Sergey wrote: > "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... When the type is statically known then there is no reason to declare the object as something else. The example makes no sense. Note that the point was that pointers are dangerous and in Ada there is less need in them as compared to C++, that is what Martin wished to demonstrate, I presume. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de