first, usigned short is uint16 and signed long is int32. size of uint16=2 while int32=4, which means No, right?
LB, I am not sure what you are referring to. Am I missing anything?
How about
uint64_t t = ...
int32_t i = static_cast<int32_t> (t);
is there any chance that i could be negative for this? I actually wrote a small program to prove it in windows on uint16 case, seems never the case. did not try it in gcc though.
uint64_t t = ...
int32_t i = static_cast<int32_t> (t);
Would result to negative value, or at least not the desired value if 2^sizeof(i*8)-1< t;
This i am not completely sure of though.
But if the resulting value is out of range for the type of i, at least in regular variables, what is left out of the range goes + from the lowest value of i.
So it probably applies here too.
@JLBorges: an implicit narrowing cast from unsigned 64 bit to signed 32 bit is allowed!? http://ideone.com/f9uTdY o_o
Why? Why in the world is this allowed?
What I mean is, why does it only generate a warning and not en error? I consider 'not allowed' to mean 'generates an error', whereas this just generates a warning so it is more deprecated than not allowed.