5 ms·
> No, it's because i lives in an area allocated at the OS level What OS? I don't have one. I have to link in init code to zero sections of ram before my embedd
by ori_b 8y ago
> No, it's because i lives in an area allocated at the OS level
What OS? I don't have one. I have to link in init code to zero sections of ram before my embedded code runs.
Sure, it got into the standard because some popular OSes like Unix zero initialized pages, but it's not a universal truth. The reason it's guaranteed in C is because of the spec.
- valarauca1 8y agoNot necessarily true. C89 only requires that static values be initialized. A modern C standard (section: 6.7.8(10)) requires static values be initialized, but what the value is initialized too be _technically_ indeterminate. There is the guide line given that integers must be zero, and pointers be NULL. But if a static storage class isn't consisting of purely integers, pointers, or (fixed sized) structures, arrays, and unions who's elements can recursively reduced to integers or pointers. Then the standard says the initialized value is indeterminate. While relatively straightforward, there is a few gotcha's.
- tom_ 8y agoThe C11 rules for static values are pretty explicit: ``` If an object that has static or thread storage duration is not initialized explicitly, then: - if it has pointer type, it is initialized to a null pointer; - if it has arithmetic type, it is initialized to (positive or unsigned) zero; - if it is an aggregate, every member is initialized (recursively) according to these rules, and any padding is initialized to zero bits; - if it is a union, the first named member is initialized (recursively) according to these rules, and any padding is initialized to zero bits; ''' I think that covers every possible value you can create, and it seems pretty non-indeterminate by my reading.
- pooppaint 8y agoDear lord sounds like you got lost from comp.lang.c. How did it get into the spec? Because Unix did it that way. Just like gets made it into the spec. It’s not like that was some willful good design. The history of C and it’s standarization is inextricably ties to the history of Unix.