floating point - nan initializers

Walter Bright newshound at digitalmars.com
Sun Feb 19 11:49:10 PST 2006


"Anders F Björklund" <afb at algonet.se> wrote in message 
news:dtah5j$2snt$1 at digitaldaemon.com...
> Walter Bright wrote:
>> That's right. The default initialization is *not* about being convenient 
>> or a shorthand. It's about being an aid to writing bug free code.
>
> So it's an error to use ints before they're initialized ?
> I thought it was "OK" to assume they all started at zero...
> You know, like in: http://www.digitalmars.com/d/wc.html ;-)

Sometimes I get lazy. :-) I'll say it's poor style, and yes, I'm guilty of 
it.

>> If there was a nan value for ints, that would be the default 
>> initialization for that, too. I'd love it if you could set a bit for a 
>> memory address that is cleared when the address is written to, and 
>> generates a hardware fault if it is read with that bit set. But there is 
>> no such thing, and nan is the best we can do otherwise.
>
> So if the int.init is ever changed to something "nan"-ish, like
> -1 or 0xDEADBEEF or something, it could stop to work later on ?

It isn't going to change, for the pragmatic reason it'll break too much 
code. There's too much water under that bridge.

> Guess this means to start using an "= 0;" explicit init value.

I think it's good style to let the maintainer know that one intended it to 
be 0. 





More information about the Digitalmars-d mailing list