Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First, reading the string "-1" as a negative number is locale dependent (it would be possible for a locale to identify negative numbers by enclosing them in parenthesis). <a href="http://www.research.att.com/~bs/3rd_loc.pdf" rel="nofollow noreferrer">Your default standard is the "classic" C locale</a>:</p> <blockquote> <p>By far the dominant use of <em>locales</em> is implicitly, in stream I/O. Each <em>istream</em> and <em>ostream</em> has its own <em>locale</em>. The <em>locale</em> of a stream is by default the global <em>locale</em> at the time of the stream’s creation (page 6). ...</p> <p>Initially, the global locale is the standard C locale, <em>locale::classic()</em> (page 11).</p> </blockquote> <p><strike>According to the GCC guys, <a href="http://gcc.gnu.org/ml/gcc-prs/2002-01/msg00693.html" rel="nofollow noreferrer">numeric overflow is allowed to fail the stream input operation</a> (talking about negative numbers that overflowed a signed int):</p> <blockquote> <p>[T]he behaviour of libstdc++-v3 is strictly standard conforming. ... When the read is attempted it does <em>not</em> fit in a signed int i, and it fails.</strike></p> </blockquote> <p>Thanks to another answer, <a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39802" rel="nofollow noreferrer">a bug was filed and this behavior changed</a>:</p> <blockquote> <p>Oops, apparently we never parsed correctly negative values for unsigned. The fix is simple. ...</p> <p>Fixed in mainline, will be fixed in 4.4.1 too.</p> </blockquote> <p>Second, although integer overflow is generally predictable, I believe it's <a href="http://dobbscodetalk.com/index.php?option=com_myblog&amp;show=A-parable-about-undefined-behavior.html&amp;Itemid=29" rel="nofollow noreferrer">officially undefined behavior</a>, so while I can't say why -32769" converts to 32767, I think it's allowed.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload