
18 Mar
2009
18 Mar
'09
4:11 p.m.
Hi Rob,
This code
produces
4294967295
on MSVC7 & 8
rather than an exception. Is it supposed to do this?
I'd say yes, since a conversion from int to unsigned int is well defined, so I would expect lexical_cast to work in the same way in this case. Consider paragraph 2 of section 4.7 of the 2003 edition of the C++ standard: "If the destination type is unsigned, the resulting value is the least unsigned integer congruent to the source integer (modulo 2^n where n is the number of bits used to represent the unsigned type). [Note: In a two's complement representation, this conversion is conceptual and there is no change in the bit pattern (if there is no truncation). ]" Regards, Eugene Wee