Explanation of static?


I've recently read a long code and could not find an explanation searching this forum and Google. I would like to know why one would do this:

static int function(int *this, int *that)
   if (this + that == something)
      return 0;
   return 1;

Now, I know what a static variable does inside functions etc., but not one page I could find use the static in defining a function.

So, how does that kind of function behave or why would anyone do so? The code that I saw was not commented at all.

Thank you very much for your responses!

"static" limits the scope of an object, be it variable or function. In this case, scope is limited to the source file containing the function.

Indeed. In your example the function "function" would not be visible to other compilations units (.cpp files) by the linker. People sometimes do that for "local" functions where they are worried that another file might use a function of the same name, which would then give a "duplicate function" error in the linker.

Ah, that explains it perfectly :) Thank you very much both of you!

And Thank You @ Awol & Nick Gammon. I’ve not seen it explained so well, so succinctly.