www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - A uint type bit shift error

reply Hiroshi Sakurai <Hiroshi_member pathlink.com> writes:
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
Dec 28 2004
next sibling parent "Thomas Kuehne" <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Added to DStress as
http://dstress.kuehne.cn/run/cast_06.d
http://dstress.kuehne.cn/run/cast_07.d

Thomas

-----BEGIN PGP SIGNATURE-----

iD8DBQFB0zZ+3w+/yD4P9tIRArRjAJ9XoRk9VEaX71bkXwwMmAnqtPNKrgCeKjbH
gBNaFTimOunP/U9v1aRnoWE=
=D4K0
-----END PGP SIGNATURE-----
Dec 29 2004
prev sibling next sibling parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
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).
Dec 31 2004
prev sibling parent "Walter" <newshound digitalmars.com> writes:
"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
Mar 09 2005