<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">When compiling without optimization it will depend entirely on whatever happens to be on the stack where the object is allocated, hence on whatever was left behind by the initialization code that executed before main was invoked. (If the init code never reached that stack depth, then consistently getting zero is expected since the stack is zero-initialized by the OS.)</div><div class="gmail_quote"><br></div><div class="gmail_quote">Example: <a href="http://melpon.org/wandbox/permlink/7BlNvpS6Hq34fqTi">http://melpon.org/wandbox/permlink/7BlNvpS6Hq34fqTi</a><br></div><div class="gmail_quote"><br></div><div class="gmail_quote">Note how the second invocation of foo() prints the value left behind by the first invocation of foo().</div><div class="gmail_quote"><br></div><div class="gmail_quote">Of course even if it consistently printed zero, that would still not be a sound way to detect unnecessary zero-initialization, since if it is uninitialized then the value that is printed is undefined, in which case consistently printing zero is just as reasonable as any other value. (Also, even it it *did* perform zero-initialization, this would be inefficient but not incorrect, hence it doesn't actually make sense to perform this test without optimization enabled.)</div><div class="gmail_quote"><br></div></div></div>