Why is char initialized to 0xFF ?
lithium iodate
whatdoiknow at doesntexist.net
Sun Jun 9 20:52:50 UTC 2019
On Sunday, 9 June 2019 at 18:27:07 UTC, Patrick Schluter wrote:
> On Sunday, 9 June 2019 at 12:19:43 UTC, Ola Fosheim Grøstad
> wrote:
>> 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…
>
> It is undefined behaviour by the definition of the standard.
> undefined behaviour includes behaviour that can be explained.
To be fair, the C standard (C11) is a bit self-contradicting
there. Variables of automatic storage duration that are not
explicitly initialized contain an unspecified value (i. e. any
valid value) or a trap representation. Types such as integers
usually don't have any trap representations so reading them
should be defined on most platforms (unless C permits some sort
of compile-time-only trap representation? not sure.). Then
there's informative(!) annex J which explicitly lists it as
undefined behavior.
More information about the Digitalmars-d
mailing list