Re: 64-bit unsigned / signed ptr conversion differences?
Re: 64-bit unsigned / signed ptr conversion differences?
- Subject: Re: 64-bit unsigned / signed ptr conversion differences?
- From: "Clark Cox" <email@hidden>
- Date: Thu, 19 Apr 2007 16:31:51 -0700
On 4/19/07, Joseph Kelly <email@hidden> wrote:
This snippet:
long long i = 12345, *p1 = &i;
unsigned long long* p2 = p1, j = *p2;
compiles with a warning in C and Obj-C, but compiles with an error in
C++: "error: invalid conversion from 'long long int*' to 'long long
unsigned int*'"
Is this a compiler bug, a standards thing ("C Language Dialect"
setting is "Compiler Default", or GNU89), or is there a flag I can
set to get C++ to be more like C in this regard, (or am I just being
dumb ;-)?
It is undefined behavior in either language. The compiler is behaving
correctly. You can either find a way to do whatever you're doing
without converting pointers like this or you can use a cast.
Interestingly, the assignments:
i = j;
j = i;
compile on either w/o errors or warnings.
Remember that converting pointers and converting what they point to
are two very different things. The conversion between signed and
unsigned integers is well-defined (for positive numbers), the
conversion between different pointer types is undefined (unless we're
talking about void*).
--
Clark S. Cox III
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden