Friday, 6 September 2013

C- Scope of functions declared static

C- Scope of functions declared static

Functions and variables declared static have internal linkage and they
have file scope and they are not visible to functions in other files.
Suppose that i declare a function like this:-
static int foo(int i);
in one file named file1.c Can I access this function from other file
file2.c through the use pointers.
I am reading a book in which it is written that it can done but I don't
know how that is possible.
And these are the exact lines:-
Because it has internal linkage , f can't be called directly from outside
the file in which it's defined.(Declaring f to static doesn't completely
prevent it from being called in another file; an indirect call via a
function pointer is still possible.

No comments:

Post a Comment