1, 2 or 3 /g/?
3 and only 3.
>>59012348
>>59012348
WTF, didnt even know 1 and 2 would compile
One shouldn't be afraid of making appropriate use of whitespace, but be reasonable. You shouldn't be thinking about splitting up your function until its parameters start pushing it above 80 characters.
static int foo()
{
}
>>59012409
With very few exceptions, newlines do not matter to a C or C++ compiler.
#1 makes it possible to grep for
^foo(
and find the definition.
>>59012429
this, but at the very least put a space between the braces and parenthesesstatic int foo() { }
>>59012466
>grep
>source
why
>>59012466
You could grep forint foo
for #2 and #3
static
int
foo
(
)
{
}
>>59012466
you would only find the first line of the definition?
>>59012348
3, what kind of question is this?
>>59012483
have you never worked on even a moderately sized project?
>working in some file
>calls a function
>where the fuck is this function defined?
>grep '^function' *.c
easy
>>59012507
Or you could just use an actual editor/IDE and right click the call and select "Find Declaration"
>>59012527
either that, or use a source-code tagging program.
GNU GLOBAL is god-tier, I'm surprised it isn't more popular.
Alternatively if your codebase has declarations like number 3, you could just grep for:static *int *foo.*(
>>59012527int
main
(void)
{
printf(
"Hello"
"World"
);
}
>>59012491
you would find where the function is defined
>>59012483
you are new
>>59012675
static int () foo{}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
static
int
foo
(
)
{
}
;
This is best
depends entirely on what the current scope is.
>>59012409
>C toddlers on /g/
>>59013412
It's fucking ugly code that shouldn't be written as such and you know it
>>59012409
They're not used a lot, the most recent example I saw #2 being used in was code for Inferno.
https://bitbucket.org/inferno-os/inferno-os/src/d0f67301aeeadce718a5e0313cee03f4ab6b71b0/emu/port/alloc.c?at=default&fileviewer=file-view-default
>>59013520
#1*
>>59012348static int foo() {
// eotihhboeuhtnihhtn
}
>>59012623
pleb#include\
"stdio.h"
int main
(
int
argc,
char
*
argv
[
]
)
{
printf
(
"Hello"
" "
"World"
"\n"
)
;
return
0
;
}
>>59014349
oh I fucked up#include\
"stdio.h"
int
main
(
int
argc
,
char
*
argv
[
]
)
{
printf
(
"Hello"
" "
"World"
"\n"
)
;
return
0
;
}
>>59014377
Now I present the "one token per line" style with proper indents#include\
"stdio.h"
int
main
(
int
argc
,
char
*
argv
[
]
)
{
printf
(
"Hello"
" "
"World"
"\n"
)
;
return
0
;
}
>>59012348static int foo(){
// shit goes here
}
fn foo() -> u32 {
}
>>59014554static int foo()
{
// shit goes here
}
FTFY
whichever clang-format spits out.
great, yet another low-hanging fruit discussion topic on which any retard who can write a hello world can have an opinion on.
>>59014572
go home scala
no one likes you
>>59012348
gofmt
/thread
>>59013439
yes, but how could you not know that C is white-spaced agnostic?
>mashing the function name up against the parameter list
You don't have to live like this.static int foo ()
{
return bar();
}
Anything but 3 is objectively and literally retarded.
>>59012416
>80 characters
I didn't realize it was still 1995. Go back to gamefaqs, dick lips.
>>59012507
>what are ctags
>what is using an IDE
>i'd rather keep to strict style so my shitty way of searching things works instead
3
On a modern monitor vertical space is much more at a premium than horizontal
People who still stretch code vertically to save horizontal space so that the code wont fill more than half their 16:9 monitor's width are fucking barbarians.
>not trying to make ASCII art that compiles
Are you some kind of, gay?
const
char
foo[1]
{
'
a
'
,
'
b
'
,
'
c
'
,
.
.
.
}
;
#include <stdio.h>
int main(){
int a = 3;
int b = 4;
int c,
d
=
5, 6;
while (true)
{
printf(
"OP is a fag \n"
);
}
}
Now that's some CSS I can get behind!
>>59014587
I always put the { in the same line
>>59014554
dood this is not js
>>59018666
Works in C and C++ too
>>59018416
>my sides
#1
#2 is reasonable, thoughint
main(int argc, char *argv[])
{
if(statement == true) {
// stuff
// other staff
} else {
// other shit
}
return stuff;
}
>>59012488
But you should know what the type returned by foo is
>>59013160
I don't know what are you trying to say
>>59012348
3
Close the thread before more stupid people talk
>>59012348
Using deprecated typed languages. You see the compute is smart enough to decide how something should be stored on memory.
>>59017586
Anon was probably just being dramatic.
>>59018619
good luck finding that one fucking opening bracket when you debug
>>59018845
we were doing fine before (You)r uneducated opinion
>>59018935
It's not an uneducated opinion.
1 and 2 are dumb and unnecessary.
>>59012348
ok I started using linux for the first time this week
what the fuck is foo
The only correct way
http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/bin/dd/dd.c?rev=1.23&content-type=text/x-cvsweb-markup
I told a guy at work, when we were talking about block opening style, that I use a newline when defining functions, but for all other cases use the same line. He looked at me like I was retarded...
;_;
>>59020852
> * Copyright (c) 1991, 1993, 1994
>The Regents of the University of California. All rights reserved.
They think they have a copyright on their code hahaha
static
int
foo
(
int
param1
,
int
param2
)
{
//do stuff
}
>>59012466
this
int
main( int argc,
char** argv ) {
functionCall( );
statements;
return 0;
}
>>59020852
this style is the best
>>59012466
>>59012507
lmao do people actually do this
static
int
foo
{
}
is the best