my cpu is amd x86-64, and os is fedora core 5 x86-64 version
gcc version 4.1.0
the program lists here
#include "stdio.h"
int main(int argc, char* argv[])
{
unsigned long long a, b;
a = 0x8000000000000000;
b = a>>1;
printf(
"a = %llu\n"
"b = %llu\n",
a, b);
a = 1<<(8 * sizeof(unsigned long long) - 1); // here give a warning
b = a>>1;
printf(
"a = %llu\n"
"b = %llu\n",
a, b);
return 0;
}
the compiler gives a warning that left shift length is more than or equal to type width.
the result is:
a = 9223372036854775808
b = 4611686018427387904
a = 0
b = 0
use gdb, "p/t 1<<63", the result is 1000000000000000000000000000000000000000000000000000000000000000, this is right
"p a = 1<<63", then a is 1000000000000000000000000000000000000000000000000000000000000000
i don't know why i cannot get 1<<63 in my c program.
if change the type "unsigned long long" to "unsigned int", the result is ok.
cannot display left shift ope
cannot display left shift operator?
line 11 is :
a = 1**(8 * sizeof(unsigned long long) - 1); // here give a warning
** is a left shift operator
use gdb, "p/t 1**63" gives t he result 1000000000000000
"p a = 1**63" , then a is right.
i don't know why i cannot get 1**63 in my c program.
if change the type "unsigned long long" to "unsigned int", the result is ok.
use 1llu << 63 the s
use
1llu << 63the suffix
lluis importand to indicate that you are using aunsigned long longgreetings