Paul Jakma wrote:
>> nice. must remember that one. :)
>> am i right in thinking that to do the below without goto would be
> difficult to do legibly?
>> ie goto enhances readibility/structure of this?
Well I can see a few ways to do this but none of them are as
clean or as easy to modify e.g.:
Use a set of nested 'if' statements, then use the error value passed
to a 'case' statement to do the releasing of resources. Main problem
here would be that the error values returned by most functions would not
usually not be fine grained enough to do the releasing of resources.
Use the 'else' branch of the 'if' statements to do the resource
This would result in a lot of repetition of commands which would have
knock on affects on how maintainable the code was as well as the
of introducing bugs. Yes you could cut and paste the lines from one
the next but you must remember if you fix a bug in one else block
to fix it in all the others.
You could check the resource handle for each resource and release it if
it was valid. This might not always be possible. Adds lots of if
to the end of your function.
I am sure there are other ways to code this type of problem.
So the goto's enchance the readability / structure / maintainability and
of this code.
I would very rarely use goto's in any of my code. They can cause a many
as they solve. This is one case where I would consider using them
Mark Fallon E-mail : Mark.Fallon at oracle.com
Senior Software Engineer Phone : +353-1-8033207
Global Product Engineering Fax : +353-1-8033221
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!