Boost logo

Boost :

Subject: Re: [boost] [lexical_cast] Strange behaviour
From: Eugene Wee (crystalrecursion_at_[hidden])
Date: 2009-03-18 12:11:54

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). ]"

Eugene Wee

Boost list run by bdawes at, gregod at, cpdaniel at, john at