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

[style] one-line functions in C

Name: Anonymous 2010-04-11 13:03


int frozen(int arg)
{
  return (arg+23);
}


OR


int frozen(int arg)
{ return (arg+23); }

int frozen(int arg)
  { return (arg+23); }


OR MAYBE EVEN SCREEN ESTATE SAVING


int frozen(int arg) { return (arg+23); }


The first version would be consistent myth my usual style, but version 2.2 looks too sweet to resist.

Name: Anonymous 2010-04-12 4:47

I can't tell who's trolling who. Where does one place an inline function if not in a header file?

And static inline is necessary because gnu99 differs from c99 which also differs from c++ in the behaviour of bare inline. In gnu99, bare inline emits a non-inline function definition. In c99 it does not. In c++ it emits a static function definition.

Instead of trying to preproc all this bullshit, it's better to simply mark it static, and just don't take the address of an inline function. Most linkers are able to merge these definitions anyway (c++ linkers generally have to in order to avoid generating gigantic executables).

Name: Anonymous 2010-04-12 4:51

>>41
Sorry, that should read gnu89. Apparently gcc fixed the behaviour in gnu99.

I don't know how clang handles it but I assume it matches the spec, since it's one of the most pedantic compilers out there. Visual studio also differs from both gcc's c modes; it doesn't support inline in c, but using __inline emits as static inline iirc.

To sum it all up, not using static inline is going to break at some point on something somewhere.

Name: Anonymous 2010-04-12 5:50

#define i int
#define rt return
#define fr frozen
#define ar arg
i fr(i ar){rt ar+23;}

Name: Anonymous 2010-04-12 6:12

This ITT thread is full of COBOL-fags plus some ``Me is smarter than ur compiler''-pussies. Great!

Name: Anonymous 2010-04-12 6:16

>>44
U MENA JAVA

Name: GvR 2010-04-12 6:17

>>1
Curly braces are evil, and now you see precisely why.

def frozen(arg):
    return arg + 23

Name: Anonymous 2010-04-12 8:02

>>46
frozen = (23).__add__

Name: Anonymous 2010-04-12 9:25

>>47
Beautiful, but that's 23+add, not add+23.

Name: Anonymous 2010-04-12 10:31

Name: Anonymous 2010-04-12 12:10

ups, i haxed their servers xd

Name: Anonymous 2010-12-09 19:11

Name: Anonymous 2010-12-21 0:57

Name: Anonymous 2013-01-19 14:41

/prog/ will be spammed continuously until further notice. we apologize for any inconvenience this may cause.

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