Is there a way to make a variable in C only accessible to the file in which it was declared?
I am asking this because I remember reading somewhere that it’s possible to do that, but I really can’t remember how to do that. Is it possible, or am I just imagining?
Using the
statickeyword will give the global variable internal linkage, meaning that the name will not be visible to other translation units. However, note that this differs from what you asked for in that:#includedirective).staticvariable which returns a pointer to it.