lexical_cast with negative number behaves differently on different machines

115 views Asked by At

I have identical versions of boost on two different devices, yet the behavior is different for

lexical_cast<uint>("-1")

The documentation states that it should give me INT_MAX (2's complement rollover) but on one machine I get an exception throw while on the other one I get INT_MAX.

1

There are 1 answers

4
wonton On

Apparently if you look at boost's code for lexical_cast the input is loaded and operated upon using code like this interpreter << arg; interpreter >> result and in the >> operator

this->setg(start, start, finish);             
std::basic_istream<CharT> stream(static_cast<Base*>(this));
stream.unsetf(std::ios::skipws);

It uses std::basic_istream so different versions of libstdc++ will cause lexical_cast to behave differently on different machines.