Michael Torrie wrote:
> Daniel Dilts wrote:
>
>> The problem is that this requires the cleanup to be done in each if block.
>> Avoiding that is one of the main purposes of the do{}while(false) block.
>> Note that the DIR * has to be released if it has been created successfully.
>>
>
> Any time you have to perform a similar cleanup for multiple code blocks,
> you might consider using the goto statement. It's there for just this
> kind of thing. Put the cleanup code at the end of the function after a
> label, and then anytime you need to abort and clean up, just goto that
> block. It's very clean and readable to do it this way. The Linux
> kernel source uses this technique a lot.
I was thinking this same thing while reading your code. Using a more
modern language, I would probably employ exceptions in this case. Unless
I'm using C++, in which case I avoid them (nearly) at all cost, mostly
because of fear of just about all things that are C++ and not Qt. :)
--Dave
--------------------
BYU Unix Users Group
http://uug.byu.edu/
The opinions expressed in this message are the responsibility of their
author. They are not endorsed by BYU, the BYU CS Department or BYU-UUG.
___________________________________________________________________
List Info (unsubscribe here): http://uug.byu.edu/mailman/listinfo/uug-list