On 9/1/2017 at 1:22 AM, matt77hias said:Doesn't the MVSC++ compiler with debug flag enabled need to generate the explicit initialization code statements? (for me VS and MVSC++ are so coupled, pretty much the same; some skin over the compiler).
Exact behavior in practice depends on what debug flags are passed to the compiler, which version of the standard libraries you're linking against (debug or release), whether or not you started the program with the debugger attached, and other stuff I'm likely forgetting. Many of these will be to use magic numbers, not zero, explicitly to help you track down what would be considered bugs in cases where the C++ standard does not require initialization, and may not initialize in Release builds.
In release builds, the compiler may make extremely aggressive optimizations about uninitialized memory, such as evaluating two mutually exclusive if statement as both being true, even though common sense would say uninitialized memory has only one value and that such a thing is impossible: https://markshroyer.com/2012/06/c-both-true-and-false/
There are some circumstances where C++ guarantees data gets zero-initialized (global data, memory returned by calloc (clear-alloc), etc.), use those if you want your memory to be zero. Debug patterns like CCCCCCCC help make sure you're not accidentally using something that just happens to sometimes return zero-initialized memory and expecting it to always be zero-initialized (when it may not be in Release builds, on other compilers, when the allocator starts to reuse freed memory, etc.)
EDIT: There are also more involved tools like https://clang.llvm.org/docs/MemorySanitizer.html which cause your program to actually crash when reading uninitialized memory, specifically so you can easily find it and fix it, instead of having strange bugs in your program which can be hard to get to the bottom of.
(Additionally, there are ways to have Visual Studio use clang, gcc, and other non-Microsoft compilers - so it doesn't hurt to be specific about what you're talking about :))