[cfe-dev] Feature/opinion request

David Chisnall David.Chisnall at cl.cam.ac.uk
Thu Oct 11 04:39:00 PDT 2012


On 11 Oct 2012, at 08:04, Unai Landa wrote:

> 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.
> 
> I think this could be an interesting compilation flag or pragma.
> 
> What's your opinion?

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.  

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.

David



More information about the cfe-dev mailing list