4 ms·
Lesser-known C coding styles
- adrianratnapala 10y agoI shan't be taking it up, but this semicolon-first style has merits. The example looks perfectly readable to me. And it is probably makes it harder to miss semicolons, because all those for one block line up in a single column. The main thing I fear is it increases the chance of an accidental: if(foo) ; do_something_i_though_was_conditional() But if you are already using braces everywhere, {then this isn't a problem}.
- turbohz 10y agoElm uses a similar style, with semicolons and commas at The beginning. The problem I have with it is that prevents easy reordering of lines, in lists or records, because they first one always starts with a curly brace.
- informatimago 10y agoI'm partial to the lisp style: #include <stdio.h> int loop(int i){ return ((i==0) ?0 :(printf("%d\n",i),loop(i-1)));} int main (void){ return loop(10);}
- Kristine1975 10y agoNice. At least if your compiler implements tail call optimization, otherwise sooner or later you'll get a stack overflow.