Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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.

share|improve this question
    
FWIW, it's not only vim. About every style I've ever encountered does it. –  delnan 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
add comment

4 Answers

This is the standard way for labels to be indented.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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)

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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