$ cat ldiv.d
import std.stdio;
import core.stdc.stdlib;
void main() {
long m = 24;
long n = 111;
ldiv_t qr = core.stdc.stdlib.ldiv(m, n);
writeln(qr);
assert(qr.quot == 0);
assert(qr.rem == 24);
}
$ dmd ldiv.d
$ ./ldiv
ldiv_t(0, 0)
[email protected](10): Assertion failure
----------------
??:? _d_assertp [0x559c0455105d]
??:? _Dmain [0x559c045404f2]
of course, using lldiv(), we get the correct result:
lldiv_t(0, 24)
but:
1) the compiler should generate warning message, when user passing D:long as c_long to ldiv().
2) both m and n in the above are small ints, even passing as long, why the result is wrong? is there another hidden bug somewhere?
Comment #1 by duser — 2022-02-19T05:47:28Z
> 2) both m and n in the above are small ints, even passing as long, why the result is wrong? is there another hidden bug somewhere?
that would be this issue: https://issues.dlang.org/show_bug.cgi?id=18117
Comment #2 by robert.schadek — 2024-12-13T19:20:40Z