Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Criticize GOTO.

Name: Anonymous 2009-06-29 10:55

Please, I'd like to hear what /prog/ thinks is silly about GOTO.

Name: Anonymous 2009-06-29 17:07

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;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List