www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - writefln + unsigned numbers

reply david <tazz gmx.at> writes:
Hello,

when playing with an array and indices that are later shifted to < 0,
I found the following rather not intuitive behaviour:

import std.stdio;
void main()
{
	uint j;
	writefln(j - 2);
}

results in 4294967294.
I'm aware of the construction of uint,
but shouldn't j be automatically converted
to a larger type providing negative numbers (long) ?

david
Apr 16 2007
parent Johan Granberg <lijat.meREM OVEgmail.com> writes:
david wrote:

 Hello,
 
 when playing with an array and indices that are later shifted to < 0,
 I found the following rather not intuitive behaviour:
 
 import std.stdio;
 void main()
 {
 uint j;
 writefln(j - 2);
 }
 
 results in 4294967294.
 I'm aware of the construction of uint,
 but shouldn't j be automatically converted
 to a larger type providing negative numbers (long) ?
 
 david
Why should it, that would cause even more confusion. In my opinion it should either be illegal (and caught at compile time) or stay as is.
Apr 16 2007