[OT] The Usual Arithmetic Confusions
forkit
forkit at gmail.com
Fri Feb 18 10:13:07 UTC 2022
On Friday, 18 February 2022 at 05:47:13 UTC, Paul Backus wrote:
>
> The behavior of converting a uint to an int is well-defined in
> D: the uint's bit pattern is re-interpreted as a signed int
> using 32-bit two's complement notation. This conversion is
> valid for every possible pattern of 32 bits, and therefore for
> every possible uint. There is absolutely no possibility of
> undefined behavior.
>
> "Undefined behavior" is a technical term with a precise
> meaning. [1] It does not simply mean "undesirable behavior" or
> "error-prone behavior" or even "behavior that violates the
> rules of conventional mathematics."
>
> [1] https://en.wikipedia.org/wiki/Undefined_behavior
The 'convertability' of a type may well be defined by the
language, but the conversion itself may not be defined by the
programmer.
I don't think it is unreasonable, to extend the concept of
'undefined behaviour' to include behaviour not defined by the
programmer.
But in any case...semantics aside...
In a language that does implicit conversion on primitive types, I
would prefer that the programmer have the tools to undefine those
implicit conversions.
That is all there is to my argument.
More information about the Digitalmars-d
mailing list