Re: regarding "goto" in C
- From: Joseph Dionne <jdionne@xxxxxxxxxxx>
- Date: Mon, 09 Jan 2006 14:07:06 GMT
Chris Dollin wrote:
websnarf@xxxxxxxxx wrote:
I personally follow only one rule regarding goto: avoid using it unless using it leads to either clearer code or faster (executing) code. This rule alone is sufficient to make the use of goto fairly uncommon in my code to the point of "spaghetti code" never being an issue. (If there's one exception it would have to be parsers -- but in those cases even the cleanest control structures don't actually lead to a clearer representation of the parser.)
I've never had to use a goto in a parser; could you unpack the reasons why you've wanted one? [email if it's likely to be wildly off-topic.]
As a *troll* I use goto often to increase execution speed, easing code readability mostly in library utilities that I write once and never look at again.
Here is my general structure.
int func(arguments)
{
int error = 0;/* lengthy function code listing */
/* at various "test" points in function the test below exists */
if (something_aint_right)
{
error = 1;
goto FINAL_func;
}FINAL_func: /* clean up any local resources, like malloc() calls, device opens, etc */
if (error)
{
/* any aditional code for error processing here. */
}return(error); }
This technique simple allows me to not code multiple in line error condition tests, and give me the ability to immediately jump out when things go bad.
.
- References:
- regarding "goto" in C
- From: M.B
- Re: regarding "goto" in C
- From: John Bode
- Re: regarding "goto" in C
- From: websnarf
- Re: regarding "goto" in C
- From: Chris Dollin
- regarding "goto" in C
- Prev by Date: Re: strcpy() - dangerous?
- Next by Date: Re: realloc question
- Previous by thread: Re: regarding "goto" in C
- Next by thread: Re: regarding "goto" in C
- Index(es):
Relevant Pages
|