Why is char initialized to 0xFF ?
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Sun Jun 9 12:19:43 UTC 2019
On Sunday, 9 June 2019 at 08:36:30 UTC, Patrick Schluter wrote:
> No, by putting NaN in d you hav e a deterministic error. In C
> and C++ you will have undefined behaviour that will vary with
> compiler, version, options, OS version, architecture, position
> of the moon, etc. and sometimes undetectable bugs.
I don't think it is undefined though… If something has an
arbitrary value, you could still compute with it, if the
algorithm takes that into account. Assuming that all bit-patterns
provides a defined value (which is the case for IEEE floating
point bit-patterns).
Anyway, the obvious advantage with having structs default
initialized to all-bits-zero is that you can have an allocator
that clears bits in the background (bypassing caches so they are
not polluted).
Then you have no penalty when allocating an array of one million
struct values. Which is very useful. Just allocate memory-chunks
that are already set to zero-bits.
You usually want an array of floating point values to be
pre-initialized to zeros. You almost never want an array of
floating point values being initialized to NaN.
More information about the Digitalmars-d
mailing list