Date: Sat, 28 Feb 2009 13:06:41 +0000 From: Dieter <freebsd@sopwith.solgatos.com> To: freebsd-amd64@freebsd.org Subject: Re: 32-bit truncation of 64-bit values Message-ID: <200902282106.VAA17590@sopwith.solgatos.com>
index | next in thread | raw e-mail
> Having just tracked down an issue caused by a pointer-to-int truncation,
Was this in C? Didn't the compiler complain?
cat demo_ptr_into_int.c ; gcc -O3 -o demo_ptr_into_int demo_ptr_into_int.c ; ./demo_ptr_into_int
/* demo_ptr_into_int.c
*
* Verify that compiler complains about truncation when
* attempting to stuff a 64 bit pointer into a 32 bit int.
*/
#include <stdio.h> /* for printf(3) */
int
main(int argc, char **argv)
{
int i;
int *p;
p = &i;
i = p;
printf("i = 0x%x p = 0x%p\n", i, p);
return(0);
}
demo_ptr_into_int.c: In function 'main':
demo_ptr_into_int.c:16: warning: assignment makes integer from pointer without a cast
i = 0xffffebc4 p = 0x0x7fffffffebc4
Adding a cast still yields a complaint:
i = (int) p;
demo_ptr_into_int.c: In function 'main':
demo_ptr_into_int.c:16: warning: cast from pointer to integer of different size
home |
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200902282106.VAA17590>
