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

The C Programming Language

Name: Anonymous 2011-10-24 21:45

Let's have a thread for the C programming language. It's an excellent language.

Name: Anonymous 2011-10-28 0:14

>>43

Haha, what an idiot!


int foo()
{
    // Create two 1000x1000 unit matrices:
    Matrix a, b, c;
    if(!Matrix_init(&a, 1000, 1000)) goto exit_foo;
    if(!Matrix_init(&b, 1000, 1000)) goto exit_foo;

    // Do something with a and b here, for example:
    if(!Matrix_init_with_matrix(&c, &a)) goto exit_foo;
    if(!Matrix_multiply_by_constant(&c, 2)) goto exit_foo;
    if(!Matrix_add(&c, &b)) goto exit_foo;
    ...

 exit_foo:
    Matrix_destroy(&a);
    Matrix_destroy(&b);
    Matrix_destroy(&c);

    return some_value;
}


He should have written that as:



int foo()
{
    // Create two 1000x1000 unit matrices:
    Matrix a, b, c;
    if(Matrix_init(&a, 1000, 1000))
    {
        if(Matrix_init(&b, 1000, 1000))
        {
            // Do something with a and b here, for example:
            if(Matrix_init_with_matrix(&c, &a))
            {
                if(Matrix_multiply_by_constant(&c, 2))
                {
                    if(Matrix_add(&c, &b))
                    {
                    ...
                    }
                }
            }
        }
    }

    Matrix_destroy(&a);
    Matrix_destroy(&b);
    Matrix_destroy(&c);

    return some_value;
}

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