I don't think there's anything inherently wrong with goto. It just requires discipline to usenot abuse. There isn't much use for it nowadays, as modern control structures are more readable and prevent the abuse.
Name:
Anonymous2009-06-29 12:14
Goto can only use labels, right? Use switch statements instead[1].
GOTO is awesome. One of the reasons that Java is so full of fail is that it lacks GOTO and thus forces programmers to use weird ass boolean variables and loops that don't loop to do what could have been accomplished in one GOTO statement.
>>14
a real programmer would just write puts("TRUE"). if + and == don't work properly, or some idiot redefines 1, 3, or 4 without considering the consequences, that's someone else's problem.
Name:
Anonymous2009-06-29 15:01
>>14 goto $(1+3==4);
Wait, can you do that in C or HIBWT?
Quote from the documentation file named "CodingStyle" of the Linux Kernel:
Albeit deprecated by some people, the equivalent of the goto statement is used frequently by compilers in form of the unconditional jump instruction.
The goto statement comes in handy when a function exits from multiple locations and some common work such as cleanup has to be done.
The rationale is:
- unconditional statements are easier to understand and follow
- nesting is reduced
- errors by not updating individual exit points when making modifications are prevented
- saves the compiler work to optimize redundant code away ;)
int fun(int a)
{
int result = 0;
char *buffer = kmalloc(SIZE);
if (buffer == NULL)
return -ENOMEM;
if (condition1) {
while (loop1) {
...
}
result = 1;
goto out;
}
...
out:
kfree(buffer);
return result;
}
>>34
What do you mean? The function in question tests if a constant-sized chunk of memory can be allocated. I wish I could remove the argument, but it's an ABI change.