On 3/31/21 2:03 PM, DLearner wrote:
On Wednesday, 31 March 2021 at 18:00:32 UTC, Steven Schveighoffer wrote:
The answer is no, the compiler does not write to memory beyond the 100
elements. That memory *might* happen to have an 8 in there. That's not
proof of anything though.
I entirely agree - I wasn't saying anything was wrong, but I _was_
surprised.
Not least because it's not chance, I changed the initial value and the
effect repeated with the new value.
It's by chance, the only correlation is probably that you are looking at
stack data that was set up to call the function that initialized the
static array. Maybe it's saving some registers and the register happens
to contain 8 (not surprising).
Or some other reason. Again, you are looking at data that the array
doesn't own, and therefore the compiler can put anything in there, it
could be 42 on another compiler, on another platform, or maybe if you
call some other functions first, it changes.
-Steve