In C, why do we use the static keyword for variables or functions with internal linkage (restricted to translation unit)? I thought that static vs dynamic refers to something happening at compilation time vs runtime. So in this context, why it is called static?
Asked
Active
Viewed 43 times
0
-
2It's a historical holdover, going [all the way back to C](https://www.javatpoint.com/static-in-c#:~:text=Static%20is%20a%20keyword%20used,variable%20is%20throughout%20the%20program.). – Robert Harvey Nov 03 '22 at 10:55
-
The `static` keyword does multiple things and some different things in different places because C was developed by different people tinkering with it in different ways. The results were a bit disorganized in how declarations behaved, and the C standard committee sought to codify that as best it could. [This answer](https://stackoverflow.com/a/63448619/298225) touches on it. – Eric Postpischil Nov 03 '22 at 10:59
-
"Static vs dynamic" in a general sense is just buzzwords. There's not one single meaning to "static" and "dynamic" in this context, the words by themselves mean nothing. – Lundin Nov 03 '22 at 11:01
-
2I think `static` was originally only used to declare local variables within a function, giving them persistent storage that was shared across all invocations of that function. Later, when they wanted a way to restrict the scope of top-level entities in a file, then reused the existing keyword rather than introduce a new one. – Tom Karzes Nov 03 '22 at 11:34
-
... and perhaps the (somewhat contorted) thought process considered that identifiers with internal linkage could be *linked* "statically", as opposed to in a separate linker pass over potentially multiple TUs. – John Bollinger Nov 03 '22 at 12:10
-
One useful document is Dennis RItchie's 1993 CACM article [The Development of the C Language](https://www.bell-labs.com/usr/dmr/www/chist.html). However, it only mentions 'static' 4 times, and there is no detailed discussion of what it means. – Jonathan Leffler Nov 03 '22 at 15:57