Re: [boost] [lexical_cast] Strange behaviour

What exactly do you think -1 is as an unsigned int? ------Original Message------ From: Robert Jones Sender: boost-bounces@lists.boost.org To: boost@lists.boost.org ReplyTo: boost@lists.boost.org Sent: Mar 18, 2009 9:03 AM Subject: [boost] [lexical_cast] Strange behaviour Trying again 'cos I mucked up the code last time! This code #include <iostream> #include <boost/lexical_cast.hpp> int main() { using namespace std; try { unsigned int u=boost::lexical_cast<unsigned int>("-1"); cout << u << '\n'; } catch(const std::exception&) { cout << "Exception" << '\n'; } } produces 4294967295 on MSVC7 & 8 rather than an exception. Is it supposed to do this? Rob. _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost Sent from my Verizon Wireless BlackBerry

On Wed, Mar 18, 2009 at 4:12 PM, <raindog@macrohmasheen.com> wrote:
What exactly do you think -1 is as an unsigned int?
I think -1 is not an unsigned int, therefore the lexical cast is beyond the range of the target type, and should issue an exception. If I wanted to reinterpret a bit pattern I'd ask for it. Regards, Rob.
participants (2)
-
raindog@macrohmasheen.com
-
Robert Jones