Subject: Re: couple of toolchain questions
To: der Mouse <mouse@Rodents.Montreal.QC.CA>
From: None <>
List: tech-userlevel
Date: 06/19/2002 00:14:58
>> 	there seem to be pointer-casting bug (or portability issue) in
>> 	GNU toolchain.  they try to cast void * (or whatever pointer) to
>> 	unsigned long long, under certain configuration, and it fails to
>> 	compile.
>Is there any guarantee that _any_ integer type is large enough to hold
>a pointer without loss of information?  I'm pretty sure there isn't in
>second-edition K&R C (which is fairly close to the first ANSI/ISO C)...

	intptr_t and uintptr_t are there, as suggested previously.  i'm not
	sure if these types are widely available on various platforms.

>> 		void *p;
>> 		unsigned long long x;
>> 		x = (unsigned long long)p;
>> 	i've modified my local tree as below, basically doing:
>> 		x = (unsigned long long)(unsigned long)p;
>Are there machines where pointers are larger than long but not as large
>as long long?  If so, that loses information unnecessarily....

	at this moment, sizeof(void *) == sizeof(int), or
	sizeof(void *) == sizeof(long) for all supported archs.

	i encountered this while making full-feature libbfd on i386.
	bfd_vma (bfd virtual memory address?) is 64bit, which is
	"unsigned long long".  void * is 32bit on i386.  and there are
	code like below which caused the problem:
		bfd_vma x;
		void *p;
		x = (bfd_vma)p;


itojun[starfruit:~/NetBSD/src/sys] grep uintptr_t arch/*/include/*.h | grep typedef|rev |sort |rev
arch/x86_64/include/int_types.h:typedef unsigned long         __uintptr_t;
arch/i386/include/int_types.h:typedef   unsigned long         __uintptr_t;
arch/hppa/include/int_types.h:typedef   unsigned long         __uintptr_t;
arch/pc532/include/int_types.h:typedef  unsigned int          __uintptr_t;
arch/sh3/include/int_types.h:typedef    unsigned int          __uintptr_t;
arch/powerpc/include/int_types.h:typedef        unsigned int          __uintptr_t;
arch/m68k/include/int_types.h:typedef   unsigned int          __uintptr_t;
arch/arm/include/int_types.h:typedef    unsigned int          __uintptr_t;
arch/mips/include/int_types.h:typedef   unsigned int          __uintptr_t;
arch/vax/include/int_types.h:typedef    unsigned int          __uintptr_t;
arch/vax/include/int_types.h:typedef    unsigned long int      __uintptr_t;
arch/sparc64/include/int_types.h:typedef        unsigned long int     __uintptr_t;
arch/alpha/include/int_types.h:typedef  unsigned long int     __uintptr_t;
arch/sparc/include/int_types.h:typedef  unsigned long int     __uintptr_t;
arch/arm/include/int_types.h:typedef unsigned long int     __uintptr_t;