Question about Static variables and functions.

This is a discussion on Question about Static variables and functions. within the C++ Programming forums, part of the General Programming Boards category; What is the different between a function that uses static variables and a static function? I know that a function ...

Question about Static variables and functions.

What is the different between a function that uses static variables and a static function? I know that a function that has static variables more or less keeps a 'running' total of the variable(s) inside it. What I am confused on is what a static function is meant to do. Is this a static function prototype?

Code:

static int add(int, int);

Or is a function just called static becase it uses static variables? If they are two different things could some one point me in the direction of where I could see some examples? Also, is there a purpose to use a static variable if main() is the only function in the program?

>What is the different between a function that uses static variables and a static function?
The difference is that static local variables are not deprecated and static functions are. So you shouldn't be using static functions in C++ anyway. But if you must know, a static function has internal linkage instead of the default external linkage. That means that only code from the same translation unit (aka. file after preprocessing) can see and use that function when it's declared as static. The C++ equivalent is an unnamed namespace: