Static Functions
Functions can be defined as
static
if they are not called from any file other than the file in which they are defined.
A function defined as
static
does not require a prototype to be declared. All other functions require prototypes to be declared.
When the
static
attribute is added to a function, the function is private to the
.c
file in which it is defined.
This can be highly beneficial as it allows for the most optimized code.
As an additional bonus, when a function is declared static, the SDK automatically generates a prototype and adds it to the top of the source file. For instance, in the code fragment:
gos_network_register_event_handler(GOS_WLAN, wlan_network_event_handler);
static void wlan_network_event_handler(uint32_t is_up)
{
GOS_LOG("Network: %d", is_up);
}
the function:
static void wlan_network_event_handler(uint32_t is_up)
is declared
static
so the function prototype is automatically added to the top of the file. This way the function can be referenced before it is defined.