char[] initialization

Hasan Aljudy hasan.aljudy at gmail.com
Sat Jul 29 05:29:21 PDT 2006



kris wrote:
> Andrew Fedoniouk wrote:
> 
>> Could somebody shed light on the subject:
>>
>> According to http://digitalmars.com/d/type.html
>>
>> characters in D are getting initialized by following values
>>
>> char -> 0xFF
>> wchar -> 0xFFFF
>> dchar -> 0x0000FFFF
>>
>> what is the idea to have string initialized by valid character code 
>> instead of 0?
> 
> 
> Try google?
> 
> http://www.digitalmars.com/d/archives/digitalmars/D/3239.html

I don't understand why the compiler should initialize variables to 
illegal values!!

OK, is it because you have to initialize variables explicitly?
Just WHY?

As far as I know, the notion that non-initialized variables are bad is a 
side-effect of the C (and C++) language, because non-inited variables 
are garbage.

However, in D (and Java .. and others), vars are always initialized.
So, if the compiler can init variables to good defaults, why should it 
still be considered a bad habit not to init variables explicitly? That 
just makes no sense to me.



More information about the Digitalmars-d mailing list