Why is char initialized to 0xFF ?
KnightMare
black80 at bk.ru
Sun Jun 9 07:48:46 UTC 2019
On Saturday, 8 June 2019 at 18:04:46 UTC, Adam D. Ruppe wrote:
> 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.
double d;
most compilers fire error "using unitialized variable".
another side "I(D compiler) will tell u nothing for that, but
u'll get a shit! haha"
ok. lets see structs now
struct S { double d; }
S s;
in most compilers s will contains zeros. in C/C++ - garbage.
men comes to D not as first language, they has troubles with
garbage in structs already, and they still forget initialize it
right (I do), so rule "all initialization is zeros" is the best
and right thing that can be.
if u dont initialize use "= void" - is good too.
but initialize ints as 0, ptrs as null, chars as #FF, doubles as
NaN - is was invented under mushrooms
men comes to D and see char=#ff,double=NaN
https://www.youtube.com/watch?v=Qsa41csyNU8
More information about the Digitalmars-d
mailing list