Bug 5132 – ~ unary operator silently different from C

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2010-10-29T12:16:00Z
Last change time
2017-07-22T21:27:37Z
Assigned to
nobody
Creator
ellery-newcomer
See also
https://issues.dlang.org/show_bug.cgi?id=16997, https://issues.dlang.org/show_bug.cgi?id=17637

Comments

Comment #0 by ellery-newcomer — 2010-10-29T12:16:39Z
~ <type> => <type> for all integer types in D, however ~ <type> => int for small integer types in C. This is a source of silently different behavior between D and C at least in unsigned integer types. example: // test.d import std.stdio; void main(){ ushort x = 0xffff; writefln("%08x", ~x+1u); } // test.c #include <stdio.h> void main(void){ unsigned short x = 0xffff; printf("%08x", ~x+1u); }
Comment #1 by bugzilla — 2012-01-19T21:21:36Z
Documented the difference.
Comment #2 by bugzilla — 2012-01-19T21:48:22Z
Documented the difference.
Comment #3 by bugzilla — 2017-07-22T21:26:06Z