Static, the worst label in programming history.

Why are programmers masochists? Seriously. Why?
At least compiler writers and pioneers of computer architecture seemed to love ambiguity, even when it is completely unnecessary.

The reason C(and later C++) used static in different contexts as different meanings is allegedly because high quantity of keywords was considered bad.

The following are the meanings of static from what I can recall:

static memory location: a place in physical memory where the program will initially allocate memory at compile-time, enduring for the life of the program.

static variable (or function) outside functions: an internally linked only variable (or function).

static variable inside a function: a variable that has program duration but local block scope.

static member function (or variable) that is shared by all the instances of that class. They live in static memory location and endure for the duration of the program as well.



These people have no clue about didactics. Clearly.

Edited by Carlos Gabriel Hasbun Comandari on
While I agree that they could have assigned more unique names to each "static" situation, in practice I don't have any issues with using static. Once you know how it should be used it is pretty obvious from context to understand what each "static" means. So I don't see what's a big deal...

What do you mean by "static memory location"? What is that?

There is one more place where "static" can be used. Not a lot of people know that, because it is only starting with C99 standard. "static" can be used for array arguments:
1
void SomeFunction(int arg1, float arg2[static 10]) { ... }

Doing this makes optimizer to know array size and it can in some cases optimize code better and provide better warnigns/errors about reading out of bounds. Clang definitively does that, not sure about gcc. MSVC doesn't support this, because it doesn't support full C99 standard. And it makes you able to use sizeof to determine size of array.

More info: https://hamberg.no/erlend/posts/2013-02-18-static-array-indices.html