This is the mail archive of the
mailing list for the GCC project.
PATCH: don't sign-extend pointers when casting to unsigned long long
- From: Matt Austern <austern at apple dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 12 May 2003 11:07:53 -0700
- Subject: PATCH: don't sign-extend pointers when casting to unsigned long long
Suppose you're on a system where pointers are 32-bit and long long is
and suppose you write "unsigned long long n = (unsigned long long) p".
results are counterintuitive. I would expect that the high 32 bits
would all be 0.
As it stands now, that may or may not be true: pointers get
This is perhaps a minor nit, since (a) the compiler will warn you if
you cast a
pointer to an integer of the wrong size; (b) neither the C nor the C++
says what happens when you cast a pointer to an integer; and (c) you
around this problem by casting to the exact unsigned type first and
again to unsigned long long. Despite all of those points, however, I
this ought to be fixed. We shouldn't be doing gratuitously unintuitive
even when users are writing technically nonportable code.
Here's a patch; test case is included. Note that the test case assumes
sizeof(long long) >= sizeof(void*). Note also that (a) I'm only
modifying the C
and C++ front ends; and (b) I'm only modifying the behavior of
expressions, as opposed to any other conversions that the compiler
Testing: applied to mainline on Linux/i686, bootstrapped (with
--enable-languages=c++), verified that there were no dg regressions and
the original test case was in fact fixed.
OK to commit?
Description: Text document