|
-
May 18th, 2009, 03:05 AM
#1
Using goto in c++ code
This may be a hot topic but I am interested in knowing what the general thought about this is. When I started to learn programming I was taught to never use goto's in the code (c++) and that this was an old way of programming.
Today, I'm working with an old c/c++ application that uses this goto command quite a lot and so I'm starting to wonder if it is not such a bad idea, at least in this case.
As an example of how it is used
Code:
int SomeFunction(int parameter)
{
int retVal = FALSE;
if (!Initiate())
goto ERROR_END;
if (!AllocateMemory())
goto ERROR_END;
if (!RunAnalysis())
goto ERROR_END;
return TRUE;
ERROR_END:
ReleaseMemory();
return FALSE;
}
In this case it is to me quite useful and makes the code more readable. Of course one could switch this to a series of if else statements but to me it would make the code more incomprehendable.
Any comments on this?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|