Path: csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ian Collins Newsgroups: comp.lang.c++ Subject: Re: Why C++ is vastly superior to C Date: Tue, 17 May 2011 11:12:53 +1200 Lines: 21 Message-ID: <93dpblFlpiU13@mid.individual.net> References: <93dhneFlpiU7@mid.individual.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Trace: individual.net daHcl0tVXxNRkM+qGhSCrA2Tlo5cE5avWPEsSJQpOAwo1NXe2+ Cancel-Lock: sha1:YcUl+e+UX49V5yNOyCMmrWbfuhU= User-Agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.9.2.9) Gecko/20101021 Lightning/1.0b2 Thunderbird/3.1.4 In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:5047 On 05/17/11 11:07 AM, Stefan Ram wrote: > Ian Collins writes: >> I normally just use RAII as the reason. Everything else else can be >> kludged in C, but not RAII. > > RAII helps to release resources even in the case of exceptions. > But C does not have exceptions. So RAII is not needed for this. It also enables early return (whether that's considered good practice is another debate!), removing the need for those awful gotos so often seen in C code. > RAII helps to do one thing »alloc()« at block entry and another > thing »release()« at block exit. This can be done in C using: > > if( a = alloc() ){ rest(); release( a ); }. It can't be done automatically in C. -- Ian Collins