JPEG Thumbnailer

Ingo Klöcker kloecker at
Tue Aug 19 22:41:24 BST 2008

On Tuesday 19 August 2008, Richard Moore wrote:
> On 8/19/08, Ingo Klöcker <kloecker at> wrote:
> > I know you will kill me for making the following suggestion. :-)
> Various phrases around using a hammer to crack a nut spring to mind.
> In the context of the question this strikes me as a rather foolish
> idea.

Indeed. Writing an error prone implementation where you have to make 
sure you do not forget to call fclose() in any of the various code 
paths (the code is question has to call fclose() in two different code 
paths) is comparable to using a hammer to crack a nut. OTOH, using a 
smart pointer with custom deleter is like using a high quality nut 
cracker to crack a nut, because a smart pointer with custom deleter is 
exactly the right tool for dealing with a FILE* resource.

Please allow me to quote from C++ Coding Standards [1] by Herb Sutter 
and Andrei Alexandrescu (a book any serious C++ developer should read 
and take by heart IMHO):

Item 13: Ensure resources are owned by objects. Use explicit RAII and 
smart pointers.

Don't saw by hand when you have power tools: C++'s "resource acquisition 
is initialization" (RAII) idiom is _the_ power tool for correct 
resource handling. [...]

C++'s language-enforced constructor/destructor symmetry mirrors the 
symmetry inherent in resource acquire/release function pairs such as 
fopen/fclose, [...].


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 194 bytes
Desc: This is a digitally signed message part.
URL: <>

More information about the kde-core-devel mailing list