HN user

abshack

20 karma
Posts0
Comments7
View on HN
No posts found.
    if( DoSomething() )
        goto fail;
    else if(DoSomethingElse())
        goto fail;
        goto fail;
    else if(DoSomethingOtherThanElse())
        goto fail;
You get a syntax error at the final else-if. A better way would probably be:
    int err = 0;
    if(!err)
        err = DoSomething();
    if(!err)
        err = DoSomethingElse();
    if(!err)
        err = DoSomethingOtherThanElse();

    if(err) goto fail;
    
I would prefer chainable commands that abstracts out the error checking though.
    err = Chain(DoSomething).Then(DoSomethingElse).Then(DoSomethingOtherThanElse);

When I did Operating Systems in University (in a group), I remember distinctly only 3 bugs that we had difficulty debugging:

* re-using a loop variable from the outer loop in an inner loop (damn you `int i`!)

* putting a char[256] on the stack when the stack size was only 256 bytes and getting stack corruption (this one wasn't me, thankfully)

* signed vs unsigned code being passed between user mode and kernel mode causing problems (no idea why it was causing issues; i just made it all unsigned and the issue went away)

In hindsight, -Wall would have probably caught everything and saved a couple hours of "wtf" at 2-3 in the morning.

Often the simplest things are the hardest to discover.