digitalmars.D.learn - Implicit conversion of int to uint
- Derek Parnell (11/11) Aug 20 2005 I just tripped over a nasty 'feature' of D.
- AJG (6/13) Aug 20 2005 I don't see one either. It should give a warning at least.
I just tripped over a nasty 'feature' of D. The two lines below compiled okay! void foo(uint A) { ... } foo(-1); The -1 was implicitly converted to 4294967295. WTF! Is there any good reason why a signed value should be implicitly converted to an unsigned value? -- Derek Parnell Melbourne, Australia 21/08/2005 9:43:30 AM
Aug 20 2005
In article <1vs47npbgypcu.1m42hzm9045ba.dlg 40tude.net>, Derek Parnell says...I just tripped over a nasty 'feature' of D. The two lines below compiled okay! void foo(uint A) { ... } foo(-1); The -1 was implicitly converted to 4294967295. WTF! Is there any good reason why a signed value should be implicitly converted to an unsigned value?I don't see one either. It should give a warning at least. Uint/int conversion can result in data problems, as seen above. I thought that sort of thing was being avoided in D with implicit conversions? I say require a cast to force conversion. --AJG.
Aug 20 2005