[Issue 6949] no warning or error if unsigned variable is compared to 0

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Nov 29 19:50:23 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=6949



--- Comment #10 from Walter Bright <bugzilla at digitalmars.com> 2012-11-29 19:50:14 PST ---
(In reply to comment #6)
> How about code like this?
> 
> void main() {
>     uint i = 0;
>     if (i == -2)
>         assert(0, "never");
> }

Equality has nothing to do with sign, i.e. there is no "signed equality" and
"unsigned equality". There's just equality.

I don't think there's any getting away from the fact that in languages like D
and C, signed and unsigned are simply different ways of viewing the same data.
For example, you can offset a pointer with both signed and unsigned values.
There is no clean separation between the two.

Some languages, such as Java, deal with this duality by defining the unsigned
type out of existence.

I've made more comments in the pull request.

-- 
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