/
Static
Static
A static variable has 3 primary uses:
A static variable in a function will retain its value between function calls.
Consider the following code snippet:
//Setup code void spike_crash_counter_output() { static uint8_t number_of_crashes = 0; number_of_crashes++; printf("Number of crashes: %d\n", number_of_crashes); } int main() { spike_crash_counter_output(); spike_crash_counter_output(); } /*Output: Number of crashes: 1 Number of crashes: 2 */
A variable declared as static in a file is a localized global, i.e. the variable cannot be seen by other files, only in the file that it was declared in.
A function declared as static in a file may only be called by functions in the same file, i.e. the function cannot be seen by other files, only in the file that it was declared in.
, multiple selections available,
Related content
Volatile
Volatile
More like this
Preprocessor Definitions
Preprocessor Definitions
More like this
Oscilloscopes 101
Oscilloscopes 101
Read with this
Code Guidelines
Code Guidelines
More like this
SPI - Serial Peripheral Interface
SPI - Serial Peripheral Interface
Read with this
C Keywords & Preprocessor Definitons
C Keywords & Preprocessor Definitons
More like this