Why is char initialized to 0xFF ?
Mike Parker
aldacron at gmail.com
Sun Jun 9 08:26:45 UTC 2019
On Sunday, 9 June 2019 at 07:48:46 UTC, KnightMare wrote:
>
> ok. lets see structs now
> struct S { double d; }
> S s;
You can set the default initializer in this case:
struct S { double d = 0.0; }
> but initialize ints as 0, ptrs as null, chars as #FF, doubles
> as NaN - is was invented under mushrooms
>
Not at all. It's quite practical for debugging. Uninitialized
variables are a pain in C and C++. Default initializing to
invalid values makes them stand out in the debugger. The drawback
is that the integrals (and bool) have no invalid value, so we're
stuck with 0 (and false).
More information about the Digitalmars-d
mailing list