Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

A question about C indent styles

Name: Anonymous 2016-07-25 7:26

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: Anonymous 2016-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: Anonymous 2016-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?

Name: Anonymous 2016-07-25 10:38

That's the Java convention.

Name: Anonymous 2016-07-25 11:20

>>1
It's more common to do that in C++ than in C.

Name: Anonymous 2016-07-25 12:04

>>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.....

Name: Anonymous 2016-07-25 14:49

>>6
Not again, dot dot dot dot dot-kun.

Name: Anonymous 2016-07-25 15:56

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: Anonymous 2016-07-25 17:08

i have worked in maine, new hampshire, new york,utah, colorado,florida,bahamas; never indented my code!

Name: Anonymous 2016-07-25 17:31

>>9
fug off :D

Name: Anonymous 2016-07-25 17:33

Check em cunts

Name: Anonymous 2016-07-26 0:09

>>11
Checked your cunt, but it was dry and scabby. Nothing else worth checking on your fucking waste of space.

Name: Anonymous 2016-07-30 22:55

i like

int
main(int argc, char *argv[])
{
//code
}


Why? I don't know, but you can search for function definition with ^main(

Name: Anonymous 2016-08-01 7:09

>>14
The fact that you can't search for "the function main" and instead have to rely on stone-age character searches is a failure of everything.

Name: Anonymous 2016-08-02 2:09

>>14
Why are you talking to yourself?

Name: Anonymous 2016-08-03 15:03

>>13
As opposed to /^int main/?
Because everyone but a complete idiot will return int from main.

Name: Anonymous 2016-08-03 17:24

I'm a suckless boy, so I just follow http://suckless.org/coding_style

Name: Anonymous 2016-08-04 22:45

>>17
• Do not use for loop initial declarations

Pig disgusting

Name: Anonymous 2016-08-05 5:40

>>17
Go back to being dead Uriel

6 uɐld ɹǝʇno ɯoɹɟ sɹǝƃƃᴉu ʎɐפ

Name: Anonymous 2016-08-05 5:54

>>18
If you're not even going to bother trying to maintain C90 compatibility, you might as well be a Java apper

Name: Anonymous 2016-08-05 9:17

>>18
they do this to be compatible with their shitty hobbyist OS whose compiler has yet to support modern C let alone any real language

Name: Anonymous 2016-08-05 11:37

>>18
I used to never use for loop inital decls but now I've realized they're actually good

Name: Anonymous 2016-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.

An interesting read on the topic.
http://prog21.dadgum.com/85.html

Name: Anonymous 2016-08-06 21:07

>>23
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: Anonymous 2016-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.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List