[–] notYOURfriend 0 points 13 points (+13|-0) ago 

Linus is the one thing standing between pure code and SJWs infecting and destroying the kernel. His philosophy of show me your code has manged to scare away all subversive elements that can't wait to "help out" by adding a Code of Conduct to a project and then finding a new host while the project sinks due to feelings being prioritized above code.

I don't know what's worse: people coding because they see dollar signs, or SJWs contributing destructive behavior (and no code).

// someone who has been coding for 20+ years just for the fun of it.

[–] hardshaft 0 points 4 points (+4|-0) ago 

Sadly you're probably right, and I fear who ever will succeed him might not have the brass and bold attitude to keep the SJWs away. They'll kill the kernel faster than you can say "Code of conduct".

[–] weezkitty 0 points 3 points (+3|-0) ago 

SJWs are worse. Because they can't be easily dismissed without an incident.

[–] analfaveto 0 points 2 points (+2|-0) ago 

Working for free is commendable, but there's nothing wrong with people wanting to be compensated for their work. If it wasn't for human greed, you'd be living in a mud hut right now and computers wouldn't even exist. I don't know anything about the Linux world and its politics, but it wouldn't surprise me if, once this Linus bloke is gone, it's the need for the Linux project to be competitive and profitable that keeps the SJWs at bay.

[–] hafen 0 points 1 points (+1|-0) ago 

Both STEM fields and Meritocracy go hand in hand, which is probably why SJW's have trouble cracking them.

Liberal Professor: Video Games Promote 'Toxic Meritocracy'; Wouldn't It Be Great If They Had More Pure Luck?

[–] ComedicGoat 0 points 7 points (+7|-0) ago 

This is beyond my understanding, quick rundown?

[–] Frank_Castle [S] 0 points 31 points (+31|-0) ago 

In C, it can be useful to have a way to test whether a certain value is known at compile-time or not. That is what this crazy-ass macro does through arcane abuse of C evaluation rules.

Consider you have some common thing you need to do in your program which does a lot of arithmetic, like this:

int myfunc(int value)
    return ((value * 1032443897) / 35468 + 934) / 34 - 34673264;

That's a lot of math operations. I mean, a modern processor still eats it in a couple of nanoseconds, probably, but if you need to do this a lot in time-critical code it might add up. The thing is, maybe in some cases you want to call it on a constant value, like this:

int myvalue = myfunc(3948);

In this case, the 3948 is compile-time constant, so the compiler could do all the math at compile time and just write the fully calculated end result right into the program binary. There would be no more cost at runtime. However, if you just call the function like that it won't do this, because C compilers usually only translate one source file at a time (ignoring a fancy new thing called LTO for a second), and so if myfunc() is defined in a different source file than the code that calls it, the compiler doesn't have the knowledge of how to do the calculation in its head at the same time as it sees the constant. It has to generate a normal function call that calculates the result at runtime.

In order to fix this, you can write a macro like this:

#define mymacro(x) (((value * 1032443897) / 35468 + 934) / 34 - 34673264)

Macros go into header files (meaning they're essentially a part of every source file they're needed in) and are always fully evaluated by the compiler at the time they're invoked. So now when you write

int value = mymacro(3948);

you can be sure that the compiler will do all the math it can with that value and calculate the final result at compile-time.

But, alas, what happens if the input parameter is not a constant? Let's say you have a function like this:

void somefunction(int input)
    int value = mymacro(input);
    ...do something cool with the value...

Now the compiler cannot do all the math at compile time, and instead has to generate code into somefunction() to do it at runtime. If you have 20 different functions that all do this, that code will be duplicated 20 times in your program, making it bloated and slow (larger programs have worse instruction cache efficiency). For that case, you would rather just call myfunction() so that all these other functions only include a small function call instruction to myfunction(), and then myfunction() contains the code to actually do the math only once.

Of course, you can just pay attention when programming and make sure you always use mymacro() or myfunction() depending on whether the input parameter is constant or not. But that is annoying and error prone, and sometimes it can actually be kinda difficult to tell whether the compiler considers a value constant or not. It would be much nicer if the compiler could just make that decision for you. With Mr. Uecker's insane new creation, you can:

#define mycalc(x) if (ICE_P(x)) mymacro(x); else myfunction(x)

Now you just use mycalc() throughout your code whenever you want to do the calculation, and the compiler will either do all the math at compile-time if it can, or output a function call to the single copy of the calculation code that's in your program binary.

[–] SuperConductiveRabbi 0 points 3 points (+3|-0) ago 

Very good explanation. Can you explain the shit going on with all the void pointers and sizeof too?

[–] tredsadsfdgfhgjkbmnc 0 points 2 points (+2|-0) ago  (edited ago)

a few things

  1. I would put money on this behavior being enabled in some in some obscure compiler flag in the near future.

  2. I never want to read code from the guy who first figured this out, I imagine its just a giant ball of spaghetti, or examples of hello world in brainfuck

[–] cosmic_climb 0 points 2 points (+2|-0) ago 

Thanks for that. A real beaty explanation.

[–] Vic_V 0 points 0 points (+0|-0) ago 

So he is a genious made it faster but no one can understand it

[–] vastrightwing 0 points 6 points (+6|-0) ago 

C++ : Where friends have access to your private members.

[–] RevanProdigalKnight 0 points 1 points (+1|-0) ago 

#define private public ftw

[–] prairie 0 points 1 points (+1|-0) ago 

Valid only if you don't include any headers, otherwise it's non-conforming. Macro names [lib.macro.names]

1 Each name defined as a macro in a header is reserved to the implementation for any use if the translation unit includes the header.

2 A translation unit that includes a header shall not contain any macros that define names declared or defined in that header. Nor shall such a translation unit define macros for names lexically identical to keywords.

[–] uvulectomy 0 points 1 points (+1|-0) ago  (edited ago)

Versus my dumbass of a C++ professor who, without fail, would leave the "L" out of "public" every single time she wrote out a class structure on the board. She always got embarrassed every time she noticed her mistake, too.

[–] the_hidden_metric 0 points 3 points (+3|-0) ago 

A real thing of beaty.

[–] SithEmpire 0 points 2 points (+2|-0) ago 

Things of beaty such as this are what gets lost when taking runtime optimisation for granted - not that I've looked much into how that works, though I presume 'literal arguments + stateless function = literal result' is a common rule.

[–] NewAccountOldGoat 0 points 1 points (+1|-0) ago 

His mouth runneth over. At sone point we'll have to accept he's an old man yelling at the clouds.

[–] timoshenko 0 points 1 points (+1|-0) ago 

Why can't it be both?

[–] theHare 0 points 1 points (+1|-0) ago 

I like programming. It’s so counter intuitive to me it’s like putting my mind in a wrestling match. It’s gay and uncomfortable, but I’m getting stronger.

load more comments ▼ (1 remaining)