Thread overview | ||||||
---|---|---|---|---|---|---|
|
December 29, 2004 A uint type bit shift error | ||||
---|---|---|---|---|
| ||||
Hi. An error occurs in following codes at the time of compile. It checked with the Windows version compiler v0.109. test.d int main() { uint a; a = 1 << 31; printf("%d\n", a); return 0; } >dmd test.d test.d(4): cannot implicitly convert expression 1 << 31 of type int to uint Thanks, Hiroshi Sakurai --------------------------------- Japanese D wiki BugTrack http://f17.aaa.livedoor.jp/~labamba/?BugTrackhttp://f17.aaa.livedoor.jp/~labamba/?BugTrack%2F10 |
December 29, 2004 Re: A uint type bit shift error | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hiroshi Sakurai Attachments: | Added to DStress as http://dstress.kuehne.cn/run/cast_06.d http://dstress.kuehne.cn/run/cast_07.d Thomas |
December 31, 2004 Re: A uint type bit shift error | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hiroshi Sakurai | I noticed this too. Sometimes it'll say something like "Cannot convert 0xfffffffff093850a to uint", which leads me to believe that it's interpreting the constant as a long (64-bit int). The 0.105 changelog says " Changed integral literal type determination to match C99 6.4.4.1." Would be interesting to see if the bug is in 0.104 or 0.105 (I missed the DMD downloads for 0.103 through 0.108). |
March 10, 2005 Re: A uint type bit shift error | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hiroshi Sakurai | "Hiroshi Sakurai" <Hiroshi_member@pathlink.com> wrote in message news:cqtmid$3no$1@digitaldaemon.com... > Hi. > > An error occurs in following codes at the time of compile. It checked with the Windows version compiler v0.109. > > test.d > int main() { > uint a; > > a = 1 << 31; > printf("%d\n", a); > return 0; > } > > >dmd test.d > test.d(4): cannot implicitly convert expression 1 << 31 of type int to uint That's right. The sign change changes the meaning, hence the message. I suggest rewriting to: 1u << 31 |
Copyright © 1999-2021 by the D Language Foundation