what does static mean?

This is a discussion on what does static mean? within the C++ Programming forums, part of the General Programming Boards category; can someone help me understand what static does?
I'm a beginner in c++....

>can someone help me understand what static does?
The static keyword has two functions in C++, when the object is in local scope to a function, static means that the object is not placed on the stack and has a lifespan equal to that of the program:

Code:

char *function()
{
char p[] = "This is a test";
return p;
}

This code will flag a warning and most likely not work because the memory for p is released when the function returns. By declaring p as static however, the function will return the proper value:

Code:

char *function()
{
static char p[] = "This is a test";
return p;
}

The second usage of static is in a global scope, such as when you are declaring a function prototype. The problem with global scope is that everything has external linkage by default, meaning that other source files can access them and possibly have a naming conflict. By declaring them as static you are telling the compiler that they do not exist outside of this particular source file. It's a good practice in data hiding.

Code:

// Only visible to this file
static char *function()
{
// Resides in memory that is not released
static char p[] = "This is a test";
return p;
}

What I can't understand is why nobody seems to think there is anything bizarre about a language that has to use the same word to mean so many different things. Static is a fine name for any one of its 4 different meanings, but is there no limit?

Ok, I can go along with static member variables and static nonmember variables, but can anybody tell me why the global function thing needs to be called static. And BTW, how did static_cast get in there?

What I can't understand is why nobody seems to think there is anything bizarre about a language that has to use the same word to mean so many different things. Static is a fine name for any one of its 4 different meanings, but is there no limit?

Everyone thinks it's bizarre for the same keyword to have wildly different meanings based on context. If you find out why it's like this, let us know.