I read that the extern keyword is implicit in the context of functions, so unless you specify otherwise using the static keyword (which if I'm not mistaken is basically a completely separate concept from the static that variables employ—they just share a keyword), they are visible to all object files. This makes sense; having the declarations be implicitly external, while technically unnecessary when the declarations are in the same file as the definition, is useful because the programmer doesn't have to type extern every time they want to use a function out of its defining file, which is more often the case than not. What seems odd to me is that it is implicit for the declarations and the definition.
With a variable, I don't need to include an extern for the definition, and in fact, while I can do this without error, my compiler gives me a warning for it.
For example, I can have mylib.h:
int var = 5;
//it isn't necessary to write this as
//extern int var = 5;
//my compiler even warns against it
and test.c
#include "mylib.h"
extern int var;
I would normally assume the implicit extern for functions to be the same, that is, if I defined int func(int par) in mylib.h, there would not be an implicit extern before it, but there would be an implicit extern for any declaration of it (such as if I declared it for use in test.c).
It also doesn't make much sense from the perspective of the extern keyword being used as a way of telling the compiler to look elsewhere for the definition, when the definition would never be external of the file it is in.
I feel like I'm missing something here.
int varinto an h-file and puttingextern int varin th c-file is not the usual way. Not sure these to Qs are dupes but I think you'll find the needed info by reading: stackoverflow.com/q/1433204/4386427 and stackoverflow.com/q/1410563/4386427int var = 5;inmylib.h, then that defines the variable. In any given program, only one file can includemylib.h— if more than one file includes the header, you get multiply-defined errors. With GCC 10.x, by default, even if you writeint var;in a header (rather thanextern int var;), you will end up with multiple definition errors — though older versions of GCC did not do that by default.statickeyword for both variables and functions limits the visibility of the named object. There are differences — you can have static variables inside functions, for example. But the concepts are sufficiently similar that saying "[staticapplied to functions] is basically a completely separate concept from thestaticthat variables employ" is an overstatement at least.