NO

Author Topic: static functions  (Read 2564 times)

PhilG57

  • Guest
static functions
« on: December 28, 2013, 03:59:41 PM »
Why would I ever code a function as "static" such as:

static int myfunction(int arg1, int arg2)
{
do some stuff here...
}


Do this specification must have to do with the visibility of the function within a single source file and/or across multiple source files in the same project?  Or, are the variables within the function affected in some way?

Seems to me the static specifier on a function means nothing.

Thanks.

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: static functions
« Reply #1 on: December 29, 2013, 05:28:05 AM »
Why would I ever code a function as "static" such as:

static int myfunction(int arg1, int arg2)
{
do some stuff here...
}


Do this specification must have to do with the visibility of the function within a single source file and/or across multiple source files in the same project?
Correct, a function declared as static is only visible with the same source file. That means you can not call such a function from a different C file of the same project, as the linker will not include any public information into the object file...
Quote
Seems to me the static specifier on a function means nothing.
See above...

Ralf

PhilG57

  • Guest
Re: static functions
« Reply #2 on: December 29, 2013, 05:22:26 PM »
Got it.  So the static specification on a function aids documentation by ensuring the function will not be called outside of the current compilation unit.  Many thanks.