News for hackers. Stuff that matters.
Re:Initialization in C++ is Seriously Bonkers by ori_b on Saturday January 05, 2019 @02:01PM (#18833512)
> 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.

Re:Initialization in C++ is Seriously Bonkers by pooppaint on Saturday January 05, 2019 @06:06PM (#18834925)
Dear 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.
Re:Initialization in C++ is Seriously Bonkers by valarauca1 on Saturday January 05, 2019 @02:53PM (#18833812)
Not 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.

Re:Initialization in C++ is Seriously Bonkers by tom_ on Saturday January 05, 2019 @04:15PM (#18834316)
The 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.