Impressed

Alex Rønne Petersen alex at lycus.org
Fri Jul 27 01:44:41 PDT 2012


On 27-07-2012 09:41, Simen Kjaeraas wrote:
> On Fri, 27 Jul 2012 06:36:57 +0200, Alex Rønne Petersen
> <alex at lycus..org> wrote:
>
>> Jumping over initialization isn't as problematic in D because
>> variables are guaranteed to have a default initialization value (if
>> not initialized to void).
>
> And how is that supposed to work, when you just skipped that piece of code?

The compiler does control flow analysis to ensure that all reads of the 
value will, at the very least, see a default-initialized variable. It's 
really quite trivial to do in the compiler.

>
>
>> It's worse in languages like C where the value of variables would be
>> undefined.
>
> It's *better* in languages like C, where the value of the variable would be
> undefined anyway, so you'd have to deal with that anyway.

Undefined behavior is never useful, better, or desirable in any way, 
shape, or form. With a well-defined default initialization value, it's 
trivial to discover that you skipped initialization. This is why D 
initializes floats to NaN, chars to 0xff, etc.

>
> I would go as far as to say this is part of the reason this is in the spec:
>
> "It is illegal for a GotoStatement to be used to skip initializations."[1]
>
>
> [1]: http://dlang.org/statement.html#GotoStatement
>

-- 
Alex Rønne Petersen
alex at lycus.org
http://lycus.org


More information about the Digitalmars-d mailing list