Are static functions in C language really invisible?
c
Solution
Remember that `#include`s work by copy-and-pasting the content of the included file. So in your example, after the `#include` has been processed, you get this:
static void show()
{
printf("I am in static show function in a.c");
}
void main()
{
show();
}
So clearly `main` can see `show`.1
The solution is to not `#include` .c files. In general, you should only `#include` header (.h) files. Your static functions shouldn't be declared or defined in the header file, so `main` will not be able to see it.
1. However, you now actually have two definitions of the `show` function, one in `a.c` and one in `b.c`. For `static` functions, this isn't a problem, but for non-`static` functions you would get a linker error.
Problem
I was told that a function defined as `static` in one `.c` file is not accessible from other files. But in the following program, I can access the `static void show()` function from another file. Is my understanding of `static` functions in C wrong? a.h (first file): ``` static void show() { printf("I am in static show function in a.c"); } ``` b.c (another file): ``` #include"a.h" void main() { show(); } ```