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.

tskuzzy
  • 732
  • 1
  • 7
  • 12
  • FWIW, it's not only vim. About every style I've ever encountered does it. –  Jun 06 '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 06 '12 at 20:11

4 Answers4

8

This is the standard way for labels to be indented.

James
  • 4,328
  • 3
  • 21
  • 25
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.

DeadMG
  • 36,794
  • 8
  • 70
  • 139
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)

AProgrammer
  • 10,404
  • 1
  • 30
  • 45
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.

adrianmcmenamin
  • 678
  • 3
  • 14