Possible Duplicates:
What does “static” mean in a C program?
Static vs global
What does “static” mean in C, giving the following example: “static struct ……..”?
And what is the diffrence between this and “struct ……” without the “static”?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Outside a function, static makes whatever it’s applied to have file scope. For example:
This function will have global linkage, and can be accessed by any other object file. You just have to declare it to use it, as is usually done in a header file:
However, if you use static in the definition, then the function is visible only to the source file where it is defined:
In that case, other object files can’t access this function. The same applies to variables:
This makes x a global variable, visible only within it’s source file. A “static struct” by itself doesn’t do anything, but consider this syntax:
This declares two global variables (p1 and p2), each of an “anonymous” struct type. If you append static:
Then static applies to p1 and p2, making them visible only within their source file.