Tracks
/
C
C
/
Syllabus
/
Static Functions
St

Static Functions in C

0 exercises

About Static Functions

Functions have external linkage by default and can be called from any other file in the project. For more on linkage please see the linkage concept. A static function can only be called within the source file where it is defined.

For example

// file scope, internal linkage
// can only be called from within this file
static void some_function()
{
    // code snipped
}

// file scope, external linkage by default
// can be called from any other file in the project
int main()
{
    // code snipped
}

Even if a function is declared in a header, if it is defined as static it will not be callable from outside of its source file. A source file could include the header, call the static function declared in the header, and compile, but the linker will fail to find the static function definition. A function marked as static in a source file should not be declared in its header file.

Edit via GitHub The link opens in a new window or tab