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.
--------------------
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

Reply via email to