I can see everyone decided to ignore me when I asked that we use the discussion page, but that's ok
Owen wrote:
is not K&R style.
is K&R style. Yes, the style for function declarations is different from that for conditional blocks.
You are right, of course. I wrote that page in a hurry and that slipped in---weird, since I never write that. Thanks for pointing it out.
Solar wrote:Generally speaking, a good style guide is short, consistent, and free of "special cases".
As such, all style guides I've ever had a hand in do things like "always put braces", and "always put braces on seperate lines". (The latter because readability matters, while screen real estate, that a premium with 800x600 or 640x400 resolutions, doesn't matter that much anymore today.)
My rule is pretty simple: Use braces when they are needed.
The best possible style guide, however, is a line of options to pass to a specific reformatter (like indent or astyle).
Maybe, but you still need to decide on the style first.
As for sizeof, I disagree with the notion that "programmers need to remember that sizeof is an operator, not a function". For virtually all uses (except taking its address), the fact that sizeof is an operator doesn't really matter, and writing it like any other function adds consistency (instead of a special case to the style guide).
That's not really true. E.g., consider the following:
This would result in undefined behavior were sizeof a function, as p doesn't point to anything at the first sequence point. As you can see, avoiding this confusion will help with such subtle problems. There are also a couple of other problems:
Code: Select all
sizeof(puts("hello, world!"));
&sizeof(foo);
although these are less realistic.
I wouldn't talk about what happens if a function taking no arguments is declared without "void". Anyone using K&R style declarations today is subject to capital punishment without further warning.
You're probably mixing up these two things:
Code: Select all
int foo(a)
int a;
{
}
// vs.
int bar( /* void */ )
{
}
The former was used in traditional C (i.e., before C89) and K&R have stopped using it as well, with the second edition of the book. I'm obviously against it as well.
bluemoon wrote:For Indentation I follow google's style that use SPACE instead of TAB; this make code looks more consistent across different editors.
It's not just Google who will give you that advice, it's mostly any sane programmer. This is irrelevant for the wiki, though so it's off-topic.