Sign in to follow this  
Japanese

comp.lang.c FAQ list Question 1.10

Recommended Posts

My understanding is really poor. I am not even able to understand what this question is saying. http://c-faq.com/decl/static.html

Share this post


Link to post
Share on other sites
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);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this