Right guys, it's been a while since I posted my Puzzle of the Week post (POTW). Apologies about the inordinate delay, I've been rather swamped at work.
This week's puzzle is going to be in C++, not C. Assume you have a resource that has to be declared as a pointer. For instance, let's say the resource is a FILE * variable. You open this resource at the top of your function.
Your problem is to ensure that the resource is closed reliably when the function exits. Note that standard C++ doesn't support a finally keyword or __finally or any other such variation, so don't bother using that one.
Post your solutions here. As usual, correct solutions will have their handles displayed on my sig-line for the next week or so.
Cheers and happy hackin'.