A strange div bug on Linux x86_64, (both dmd & ldc2): long -5000 / size_t 2 = 9223372036854773308
H. S. Teoh
hsteoh at quickfur.ath.cx
Thu Aug 13 10:10:34 UTC 2020
On Thu, Aug 13, 2020 at 07:22:18AM +0000, mw via Digitalmars-d wrote:
[...]
> void main() {
> long a = -5000;
> size_t b = 2;
> long c = a / b;
> writeln(c);
> }
You're mixing signed and unsigned values. That's generally dangerous
territory where integer promotion rules inherited from C/C++ take over
and cause sometimes weird effects, like here. Changing integer promotion
rules will probably never happen now, because it will cause massive
*silent* breakage of existing code. So, in the spirit of defensive
programming, I recommend avoiding mixing signed/unsigned values in this
way.
T
--
It said to install Windows 2000 or better, so I installed Linux instead.
More information about the Digitalmars-d
mailing list