What's interesting here is that the code with C-style memset actually produces less assembly instructions than the code with C++-style {} to zero-init the array. Even with /O3 optimization. Now, I know that less instructions doesn't necessarily mean it's more optimal, and of course I am aware that this is most likely insignificant, but anyone have a guess as to why the it's so different? The code that uses {} for initialization has more mov instructions and a jmp. Do these two pieces of code actually have different behavior that I'm missing? Just figure I'd ask; I'm not really expecting anyone to know (unless you're an MSVC dev, lol).
clang compiles the logic into a simple xor/ret (zero-out and return)!
gcc is less optimal, but both code excerpts compile to the same assembly.
It seems msvc is the odd man out here.
Huh you're right, Microsoft docs don't actually say anything about /O3, I must've just assumed that was a thing. But /O2 still produces more code with the uniform initialization version (x86 and x64), still disappointing.
Using x64 msvc v19.28 with /O2, the relevant assembly is below.
The only difference is the extra test (bitwise logical 'and', ignoring result)
and the conditional jump instruction (jump if result was zero).
It's like the uniform init is doing an automatic test for a failed allocation.