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,7fcf9180e7ba7ab1 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news1.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nntp.club.cc.cmu.edu!feeder.erje.net!newsfeed.straub-nv.de!nuzba.szn.dk!pnx.dk!news.buerger.net!LF.net!news.enyo.de!not-for-mail From: Florian Weimer Newsgroups: comp.lang.ada Subject: Re: A suggestion for resource management Date: Sat, 21 Aug 2010 21:47:05 +0200 Message-ID: <87d3tb7npi.fsf@mid.deneb.enyo.de> References: <8762z4gcoi.fsf@mid.deneb.enyo.de> <1q8io375n581c$.7mbvmavnyzyy$.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: idssi.enyo.de 1282420025 5794 172.17.135.6 (21 Aug 2010 19:47:05 GMT) X-Complaints-To: news@enyo.de Cancel-Lock: sha1:Lw4MBxhsphBRf5UaGX3ra7FIJDM= Xref: g2news1.google.com comp.lang.ada:13582 Date: 2010-08-21T21:47:05+02:00 List-Id: * Dmitry A. Kazakov: > On Sat, 21 Aug 2010 18:20:29 +0200, Florian Weimer wrote: > >> procedure Test_External_Formats is >> ... >> COBOL_File : File_Type; >> ... >> >> begin >> Open (COBOL_File, Name => "Some_File"); >> pragma Scoped (Close (COBOL_File)); >> >> loop >> ... >> exception >> when End_Error => ... >> end Test_External_Formats; > > What is wrong with having a destructor for File_Type? If the language is to > be extended why not to fix that first? You can't always change libraries in that way. Adding destructors has both syntactic and run-time overhead. The run-time overhead can be minimized by a sufficiently advanced compiler (perhaps relying on whole-program optimization to detect the lack of task aborts). I'm more concerned with the syntactic overhead. There are some cases where the destructor solution doesn't really apply. For instance, the cleanup operation might need two parameters, one denoting the object, and a second one decribing where to put it.