comp.lang.c FAQ list Question 1.10

Started by
1 comment, last by Japanese 17 years, 10 months ago
My understanding is really poor. I am not even able to understand what this question is saying. http://c-faq.com/decl/static.html
Advertisement
In C, a variable or function can be declared static. Declaring a function or variable static at file scope gives the function or variable internal linkage, which means that the function or variable does not get its symbol name exported in the object file. That way you can have two functions or variables named the same thing in different source files. For example, if you had this:
file1.c:
void my_function(void) {  printf("file1.c");}

file2.c
void my_function(void) {  printf("file2.c");}

You would get a link error when linking these two files together because you have two definitions of my_function() in two different source files. However this would work:
file1.c:
static void my_function(void) {  printf("file1.c");}

file2.c
static void my_function(void) {  printf("file2.c");}

The question asks if all the declarations for a static function or variable need to have the static keyword. So this is a function declaration:
static void my_function(void);

So is this:
void my_function(void);

These are declarations for a function named the same thing. The question is asking if every time you make a declaration for a static function, if you need the static keyword. That is, if something like this is legal:
static void my_function(void);void my_function(void);

Or if you need to do something like this if you declare the function multiple times:
static void my_function(void);static void my_function(void);

Great Explanation, Thanks :)

This topic is closed to new replies.

Advertisement