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

GOTO

Name: Anonymous 2010-10-26 22:52

    why do people hate gotos again? my prof said it decreases readability but.....

    Top:


    ........


    goto Top;

    GEE WONDER WHAT THE FUCK I DO IM SO FUCKING STUMPED AS TO WHAT THE PROGRAM WILL DO HERE

    I mean really why are they so bad?

Name: Anonymous 2010-10-27 0:31

Because ENTERPRISE QUALITY

void ENTERPRISE_C()
{
    int err = 0;
    char *buf1 = malloc(1);

    err = func1(buf1);
    if (!err)
    {
        char *buf2 = malloc(2);
        err = func2(buf1, buf2);
        if (!err)
        {
            err = func3();
            if (!err)
            {
                err = func4(buf2);
            }
        }
        free(buf2);
    }
    free(buf1);
}


is much more readable than the equivalent using a goto to jump to a cleanup in case of an error. Especially as functions get larger.

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