cansi-cglobal-functions

Are all functions in C global?


Is it possible that a function in ANSI C cannot be accessed from some other file? How and when functions have limited access? At first I thought that if a function is not included in any header it's private. But it doesn't seem to be the case.


Solution

  • Are all functions in c global?

    No. For one thing, what many call (sloppily) global, the C Language calls file scope with external linkage.

    Also, even in a translation unit (a fancy way to say "preprocessed C file"), a function identifier is only visible (in scope) from its declaration to the end of the translation unit (or even the enclosing block).

    To give a function identifier internal linkage (so another function or object of the same name can exist in a different object file) you use the static keyword.