Is there any particular reason why it is so uncommon to put the opening brace of a function on the same line as the function declaration? As in int main (int argc, char* argv[]) { /* ... */ return 0; } The vast majority of C code examples I've seen put the opening brace on its own line in functions, even when they don't do so for if and while statements and so on. Is there any reason for this apparent inconsistency? Personally, I tend to use the above style for everything - functions, loops, structs, etc. And while that kind of brace style is widespread in K&R/1TBS style, it seems to be almost never used for functions.
Name:
Anonymous2016-07-25 9:21
Because we're no longer working on 25-line text terminals, and have the vertical space to use for extra clarity purposes now.
Name:
Anonymous2016-07-25 10:20
>>1 Possibly related to old-style func declarations: main(argc, argv) char *argv[]; { /* ... */ ...?
>>2 You mean for readability? That you can see easily where functions start when scrolling over source?
>>5 Actually you didn't provide proof of that. None whatsoever because it is really, really wrong. Your post is disregarded. Don't like it? Only make posts with substantiated claims next time.....
I can't claim to know why K&R chose to brace their functions as they did, but a common rationalization is that functions are top-level-only constructs in C (that is, you can't nest them), so their bracing style should be different to reflect this. See for instance the Linux kernel style guide.
Name:
Anonymous2016-07-25 17:08
i have worked in maine, new hampshire, new york,utah, colorado,florida,bahamas; never indented my code!
>>18 I used to never use for loop inital decls but now I've realized they're actually good
Name:
Anonymous2016-08-06 17:23
>>1 Eternal code style wars. You can as well write int main (int argc, char* argv[]) { foo(); bar(baz); return 0; } and no compiler should complain. Useful when you have a ton of short functions and can fit to see everything without scrolling. Code formatting is not a problem, that's what you have syntax highlighting for.
Now when you were in there, would you take the time to "correct" the formatting? [...] If you do decide to make those additional fixes, who is actually benefiting from them?
I do, because my autism stops after investing 5 seconds in formatting it and I can then concentrate on the actual problem.
Name:
Anonymous2016-08-06 21:16
>>24 The program is an abstraction. When memory is allocated and used to store values, the state of the computer changes.