5132 – ~ unary operator silently different from C

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5132 - ~ unary operator silently different from C
Summary: ~ unary operator silently different from C
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Linux
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
Reported: 2010年10月29日 12:16 UTC by Ellery Newcomer
Modified: 2017年07月22日 21:27 UTC (History)
2 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Ellery Newcomer 2010年10月29日 12:16:39 UTC
~ <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 Walter Bright 2012年01月19日 21:21:36 UTC
Documented the difference.
Comment 2 Walter Bright 2012年01月19日 21:48:22 UTC
Documented the difference.


AltStyle によって変換されたページ (->オリジナル) /