[Issue 10093] wrong unsigned arithmetic
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu May 16 13:07:39 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10093
--- Comment #10 from luka8088 <luka8088 at owave.net> 2013-05-16 13:07:39 PDT ---
(In reply to comment #9)
> (In reply to comment #8)
> > The original issue was:
> >
> > auto offset = text1.length - text2.length;
> > func(offset);
> >
> > and offset turned out to be around 4294967291
> >
> > I was thinking, setting a uint to a negative value is kind of an overflow,
> > should it maybe be treated the same way like array bounds and be checked by
> > druntime (with optional disabling in production release)?
>
> Well, that's probably something the compiler can't warn about. Not statically,
> that's for sure.
> You can use a custom type which checks for bound overflows, and fallback to
> regular int for release builds.
Yeah, I could, but should that maybe be in druntime?
Also...
void main () {
auto a = 5 - 10u; // 4294967291u
auto b = 5u - 10; // 4294967291u
}
Why are they both unsigned?
I will take this to the forum.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list