3

I noticed that in the Vim automatically indents labels in a rather unintuitive way (IMHO).

int main(void) { 
    goto end;

end:
    return 0
}

Are there any style guidelines for labels?

For the faint-hearted, the goto's I am using are for error handling in a controlled and structured manner.

  • FWIW, it's not only vim. About every style I've ever encountered does it. – user7043 Jun 6 '12 at 18:19
  • 1
    If you put landmines in a field, the sign for them should rather stick out... Not bashing on goto, but it's as dangerous, while still useful in limited cases. – K.Steff Jun 6 '12 at 20:11
7

This is the standard way for labels to be indented.

4

I've seen this used for the syntactically identical access specifiers in C++. It's a good thing- it makes the labels very visible, which they really should be.

4

It has been the usage to unindent labels in all languages I've used (included ASM and fixed form FORTRAN where it was mandatory). The only variation I've seen is that the unindent may be the half of the usual indent. In your case, that would have been:

int main(void) { 
    goto end;

  end:
    return 0
}

(case label in switches in C and C++ are often indented in the same way, but that's not as universal)

1

My view is that the labels should be unindented - and this is what I do when I write C.

The labels are not executable, they are closer to function declarations than anything else (in that they mark a new point of execution) and you don't indent function declarations, do you?

But in the end it is a matter of taste. I think it's easy to spot the labels and their purpose if they are unindented.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.