why does EGCS tell me 1 << 64 = 4294967296?

Brians0@aol.com Brians0@aol.com
Sun Aug 9 04:40:00 GMT 1998


I'm using EGCS 1.0.3 with Cygwin32 B19.1 on Windows 95, which has 64-bit
unsigned long longs. I've noticed that the result of
"static_cast<unsigned long long>(1) << 64" is 2^31. Is this what it is
supposed to be? I would expect this to result in zero (0), since it
would/should shift out all nonzero bits. Am I incorrect, or is EGCS?

When i build and run the code below, the output is: 

static_cast<unsigned long long>(1)
   << (sizeof(unsigned long long) * 8) =
   4294967296

---------------------------------------------------------

int main()
	{
	cout << "static_cast<unsigned long long>(1)" << endl
		<< "   << (sizeof(unsigned long long) * 8) =" << endl
		<< "   " << (static_cast<unsigned long long>(1)
		<< (sizeof(unsigned long long) * 8)) << endl;
	return 0;
	}



More information about the Gcc-bugs mailing list