• calcopiritus@lemmy.world
    link
    fedilink
    arrow-up
    2
    ·
    3 days ago

    Can confirm. I have to do this all the time. Some coworkers just delete it, and I have to explain the situation every time when they see in the git blame that I put that semicolon there.

    As someone pointed out in another comment, in switch statements you should just start a new scope with {}. But in actual labels it’s just better to put a load-bearing semicolon. You don’t need to put it in another line though, I just put them like this:

    int main() {
        int *a = malloc(sizeof(*a));
        if (init_a(a) <= 0) {
            goto err;
        }
        do_something(a);
    err:;
        int ret = 0;
        if (a == NULL) {
            ret = -1;
        }
        free(a);
        return ret;
    }