Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 852
avivgood2 Avatar asked Dec 22 '22 18:12

avivgood2


1 Answers

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.

like image 50
Jens Avatar answered Jan 02 '23 19:01

Jens