A "unsigned long long " problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.
-- 
View this message in context: http://www.nabble.com/A-%22unsigned-long-long-%22-problem-tf2028042.html#a5577355
Sent from the gcc - Help forum at Nabble.com.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux