Why is char initialized to 0xFF ?

Adam D. Ruppe destructionator at gmail.com
Sat Jun 8 18:04:46 UTC 2019


On Saturday, 8 June 2019 at 17:55:07 UTC, James Blachly wrote:
> char is a UTF8 character, but 0xFF is specifically forbidden[3] 
> by the UTF8 specification.

And that is exactly why it is the default: the idea here is to 
make uninitialized variables obvious, because they will be a 
predictable, but invalid value when they appear.

Same reason why floats are nan and classes are null btw. `int` is 
the exception as being default initialized as something that 
happens to be really useful.

(and arrays kinda are special too. technically they are null, but 
the runtime will automatically allocate null arrays when needed, 
so it works transparently anyway... and ends up being super 
useful)


More information about the Digitalmars-d mailing list