Slava V Slava V - 1 year ago 63
C Question

What is a "static" function?

The question was about plain functions, not

methods, as clarified in comments.

Ok, I understand what a
variable is, but what is a

And why is it that if I declare a function, let's say
void print_matrix
, in let's say
) and include
- I get
"print_matrix@@....) already defined in a.obj"
, BUT if I declare it as
static void print_matrix
then it compiles?

UPDATE Just to clear things up - I know that including
is bad, as many of you pointed out, I just do it to temporarily clear space in
until I have a better idea of how to group all those functions into proper
. Just a temporary, quick solution.

Answer Source

static functions are functions that are only visible to other functions in the same file (more precisely the same translation unit).

EDIT: For those who thought, that the author of the questions meant a 'class method': As the question is tagged C he means a plain old C function. For (C++/Java/...) class methods, static means that this method can be called on the class itself, no instance of that class necessary.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download