From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3258 invoked by alias); 30 Jul 2008 12:54:09 -0000 Received: (qmail 3250 invoked by uid 22791); 30 Jul 2008 12:54:08 -0000 X-Spam-Check-By: sourceware.org Received: from hoat.troll.no (HELO hoat.troll.no) (62.70.27.150) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 30 Jul 2008 12:53:49 +0000 Received: from hoat.troll.no (tedur.troll.no [62.70.27.154]) by hoat.troll.no (Postfix) with SMTP id B095720545 for ; Wed, 30 Jul 2008 14:53:46 +0200 (CEST) Received: from gar.trolltech.de (gar.trolltech.de [10.4.0.24]) by hoat.troll.no (Postfix) with ESMTP id 961D92047F for ; Wed, 30 Jul 2008 14:53:46 +0200 (CEST) From: =?utf-8?q?Andr=C3=A9_P=C3=B6nitz?= To: gdb@sourceware.org Subject: Re: Move GDB to C++ ? Date: Wed, 30 Jul 2008 15:39:00 -0000 User-Agent: KMail/1.9.9 References: <487658F7.1090508@earthlink.net> <200807301357.00658.apoenitz@trolltech.com> <200807301212.m6UCCjHj007466@brahms.sibelius.xs4all.nl> In-Reply-To: <200807301212.m6UCCjHj007466@brahms.sibelius.xs4all.nl> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200807301456.11947.apoenitz@trolltech.com> X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2008-07/txt/msg00321.txt.bz2 On Wednesday 30 July 2008 14:12:45 Mark Kettenis wrote: > Dream on. Well, I was not trying to get to a personal level. > How is xfree() different from delete? Oh you have smart > pointers. Depends on whether you consider, say, std::string a smart pointer. > You'd better make sure you use them consistently in your > code, otherwise you end up getting yourself in the confused state > where you can't even tell whether there's a missing delete or not. If objects own their resourcs, 'delete' is rarely needed outside their destructors. > And then you decide to use a third-party C++ library. Now you're > almost certainly using your smart pointer inconsistently, or worse, > have smart pointers with different semantics. I never, ever, mentioned smart pointers. I am talking about using very basic C++ features like destructors. Take as an example from the first file I opened 'prompt_for_continue'. There's an xfree in there, needed in one codepath, not needed in the other. Not exception safe btw, but then, we do not have exceptions, right? { char *ignore; ... ignore = gdb_readline_wrapper (cont_prompt); .... if (ignore) { ... xfree (ignore); } ... } With a C-with-classes approach that could be made to look like { ... string_t ignore = gdb_readline_wrapper (cont_prompt); ... if (ignore) { ... } ... } So instead of having the code spread over 39 lines (1680..1719 in utils.c) the code is spread over _5_ lines, it saves more than a dozen keystrokes to create, and you do not even have to think about whether the xfree call goes into the if, or outside, or whatever. And see: No 'delete'. No smart pointers. No magic. > Yes, C++ has some features that make memory management easier in > theory. But they're not the magic bullet that their proponents claim > them to be. I am not argueing that it is a silver bullet. I am saying it helps in a fairly wide range of situations when used cautiously. Andre'