holding 2^63 -1 in long long
<p>I ran the following two pieces of code on Windows XP (Code:Block, MinGW),  and Ubuntu (11.04,  G++)</p>

<p>I have trouble running the following code</p>

<pre><code>#include &lt;iostream&gt;

using namespace std;

int main(){

    long long a = 9223372036854775807;
    cout &lt;&lt;  a;
    return 0;

}
</code></pre>

<p>That number is 2^63 -1.  But I will get an error stating:</p>

<blockquote>
  <p>C:\Documents and Settings\JohnWong\My
  Documents\codeblock\343_hw_1\main.cpp|9|error: integer constant is too
  large for "long" type|</p>
</blockquote>

<p>On ubuntu - it compiled, but the answer retunred is  9223372036854775808,  notice the 8 at the end....</p>

<p>Now if I run this code, using the power function, I am okay.</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;math.h&gt;
using namespace std;

int main(){

    long long a = pow(2,64);
    cout &lt;&lt; "a:   " &lt;&lt; setprecision(20) &lt;&lt; a &lt;&lt; endl;
    cout &lt;&lt; "a-1:   " &lt;&lt; setprecision(20) &lt;&lt; a-1 &lt;&lt; endl;
    cout &lt;&lt; "a-2:   " &lt;&lt;  setprecision(20) &lt;&lt; a-2 &lt;&lt; endl;
    cout &lt;&lt; "a+0:   " &lt;&lt; setprecision(20) &lt;&lt; a+0 &lt;&lt; endl;
    cout &lt;&lt; "a+1:   " &lt;&lt; setprecision(20) &lt;&lt; a+1 &lt;&lt; endl;
    cout &lt;&lt; "a+2:   " &lt;&lt; setprecision(20) &lt;&lt; a+2 &lt;&lt; endl;
    cout &lt;&lt; "a+3:   " &lt;&lt; setprecision(20) &lt;&lt; a+3 &lt;&lt; endl;

    return 0;
}
</code></pre>

<p>I will get the values I want (anything from +1 will cause an overflow, that's okay).</p>

<p>On Ubuntu the outputs looks the same. Good.</p>

<p>So what's going on here? Why constant is not good??? 
I even tried  intmax_t  and int64_t  as datatype running the first code.</p>

<p>Can someone explain this behavior? Thanks! </p>
