<br><br><div class="gmail_quote">On Thu, Oct 11, 2012 at 6:08 PM, Jordan Rose <span dir="ltr"><<a href="mailto:jordan_rose@apple.com" target="_blank">jordan_rose@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im"><br>
On Oct 11, 2012, at 4:39 , David Chisnall <<a href="mailto:David.Chisnall@cl.cam.ac.uk">David.Chisnall@cl.cam.ac.uk</a>> wrote:<br>
<br>
> On 11 Oct 2012, at 08:04, Unai Landa wrote:<br>
><br>
>> Hello, I have the idea of a flag that emulates D behavior on variable initialization, I mean initialize all members to 0 by default, and allow explicit modify this behavior on performance sensitive code.<br>
>><br>
>> I think this could be an interesting compilation flag or pragma.<br>
>><br>
>> What's your opinion?<br>
><br>
> I quite like this idea as a language feature, but it has limited use as a compiler-specific extension.  You can't write code that relies on this behaviour without becoming completely compiler-dependent, and it will hide bugs that will appear with other compilers.  Given the reality of C, I'd prefer improvements to the used-uninitialised warnings, if there are any cases that they still miss.<br>

><br>
> Adding = 0 to a declaration is not much effort if required, and it's often useful to have a variable in an undefined state at the start so that the compiler can check that it is initialised in every code path.  It's easy for a default initialisation to accidentally propagate when it isn't intended.<br>

<br>
</div>This does seem like something a tool could do, though. Normally we have the '= 0' fixit on a note for -Wuninitialized; maybe we could have a mode where that particular fixit is applied anyway? (An extension to 'clang-check -fixit'?)<br>

<br>
Just throwing out ideas!<br>
<span class="HOEnZb"><font color="#888888">Jordan<br>
</font></span><div class="HOEnZb"><div class="h5"><br></div></div></blockquote><div><br>I agree with David though, the problem of uninitialized integrals is that they do not have any sentinel values (unlike pointers, by the way, for which null initialization never hurts).<br>
<br>If you ever set a default, then you lose the capability of the compiler to tell you that the default may leak outside the current scope, because as far as the compiler is concerned this default is a perfectly reasonable value to have for an integer.<br>
<br>In other words, you are just trading technical automatically detectable defects for functional hidden ones.<br><br>I find it much easier to run with `-Wmaybe-uninitialized` on. And in the cases it's missed, I'd prefer for debug builds to stop zero-initializing everything and let the software crash... that's what debug builds are for!<br>
<br>-- Matthieu<br></div></div>