Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Post History

77%
+5 −0
Q&A 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 thr...

1 answer  ·  posted 1y ago by Lundin‭  ·  last activity 9mo ago by Lorenzo Donati‭

#1: Initial revision by user avatar Lundin‭ · 2022-11-14T10:51:35Z (over 1 year ago)
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?