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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,147f221051e5a63d X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local02.nntp.dca.giganews.com!nntp.bt.com!news.bt.com.POSTED!not-for-mail NNTP-Posting-Date: Mon, 19 May 2008 09:37:12 -0500 From: Brian Drummond Newsgroups: comp.lang.ada Subject: Re: memory management in Ada: tedious without GC? Date: Mon, 19 May 2008 15:40:45 +0100 Reply-To: brian@shapes.demon.co.uk Message-ID: References: <4ddef8bf-b5b1-4d7e-b75b-386cd6c8402c@l17g2000pri.googlegroups.com> X-Newsreader: Forte Agent 1.7/32.534 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Usenet-Provider: http://www.giganews.com X-AuthenticatedUsername: NoAuthUser X-Trace: sv3-R5wqQTltGrTknCaVQLlUCbnfguztiMJEWgUxnYc5z5ITYR+Xi4brBpVFoSc4rGFVe7r+WVHes2HWPUu!BjZynCcshEzgV9HY5GTsNWlPhTbKC2HwcJaN4P5Omw5YRtwgimIiXKLdQdSr39uYxdJUUL/83Ccs!nEg= X-Complaints-To: abuse@btinternet.com X-DMCA-Complaints-To: abuse@btinternet.com X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.38 Xref: g2news1.google.com comp.lang.ada:241 Date: 2008-05-19T15:40:45+01:00 List-Id: On Sun, 18 May 2008 09:06:55 +0100, Simon Wright wrote: >Brian Drummond writes: > >> Which explained to me how changing from ptr to auto_ptr (presumably >> to make code safer!) can introduce a spectacularly silly bug, >> completely statically determinable, but which the compiler allows >> just fine and lets the code die with a segfault. > >Is auto_ptr the one where assignment moves the content? "b = a;" means >that a is now null and b references the previous content of a? > >If so, it seems to me that it's the concept that's spectacularly >silly! (I considered introducing an auto pointer into the Booch >Components, but then thought about using it .. I can see that there >might be a use within a very narrow scope, but a standard ref-counted >smart pointer works just as well. No doubt there is an appropriate >usage idiom?) That's the one. It's maybe not spectacularly silly; I can see how it would help in other circumstances, but not here. Maciek is probably right that one or more of scoped_ptr, unique_ptr or shared_ptr would be a better choice, but that is where I want to part company with C++[+STL] - that looks like four new mechanisms to increase complexity, without eliminating the basic problems of ptr. I would prefer to catch problems at (or even before) the compiler, rather than as here, let them manifest at runtime. So, having assigned b=a, at the very least, any further references to 'a' in the same block ought to be grounds for compilation failure. But apparently not, at least in this compiler (gcc). - Brian