Post History
Whenever declaring a variable in C outside a function at file scope or when specifying it as static, it gets assigned a life time known as static storage duration. Meaning it will be accessible thr...
#1: Initial revision
How to perform initialization of static storage variables in embedded systems?
Whenever declaring a variable in C outside a function at _file scope_ or when specifying it as `static`, it gets assigned a life time known as _static storage duration_. Meaning it will be accessible throughout the whole execution of the program. Such variables are typically allocated in one of two RAM segments most often named `.data` or `.bss`: - `.data` is used for all static storage duration variables that were explicitly initialized by the programmer to a value other than zero. - `.bss` is used for all static storage duration variables that are initialized to zero. Also as per C language rules, any static storage duration variable which is not initialized to a value explicitly, gets implicitly initialized to zero and therefore ends up in `.bss`. In case of pointers, they are initialized as null pointers. On a PC/hosted system, everything including the executable code is simply loaded into RAM at once by the OS. But in case of microcontrollers we have no such thing and often prefer to execute code out of flash/non-volatile memory. When starting up a new software project in any microcontroller IDE, I am often given an option "minimal/fast start-up" versus "ANSI/ISO/standard start-up". This seems to refer to if these initialization rules should be used or not. How are these variables initialized in case I pick "minimal" start-up? What are the advantages and disadvantages of this feature?