What is the difference between a normal and static function?
Most people try to explain it in terms of class level and instance level... I am working in C, not for computer but a micro-controller... There are interrupt service routines involved. The manual of the compiler says defining an ISR like: void interrupt ISR11(void) is sufficient. But that was not working. And then after a lot of search I found an example on the web where the guy had defined it as staticvoid interrupt ISR11() and it worked. I wonder why...
So I just need to know the difference between a normal function and a static one, just in that context. Thank you.
For global functions, all 'static' means is that the function is not externally linked (basically, it can't be seen outside of the current source file).
But in C, ISR11() and ISR11(void) mean 2 different things. So maybe that's what made the difference here.
Empty parenthesis in C means the same thing as the ellipsis in C++: The function can take any number of parameters, and those parameters can be accessed with the va_args stuff in stdarg.h.
However in C++, empty parenthesis means the same thing as (void): The function can't take any parameters.
In regular C (no classes), a static variable or function is a variable or function that only exists for the current code file. In other words, the linker cannot get to these and therefore other object files from other code files cannot use them.
Example: sttatic void *myVar;
The above is visible in the code file it resides ONLY. If you have the above in a header file, and if you include that header file in other code files, you will actually be working with different copies of the variable.
void *myVar;
The above on the other hand, can be made available to other code files (and therefore it is a global variable) by means of:
externvoid *myVar;
inside a header file that you would include in other source files in the project. Unlike the first example, this inclusion will make all code files access the same memory location, effectively making the variable global.