Subject: Re: new sysctl(KERN_PROC, ...) interface (was: sysinfo(2))
To: matthew green <mrg@eterna.com.au>
From: Simon Burge <simonb@netbsd.org>
List: tech-kern
Date: 04/18/2000 12:09:50
matthew green wrote:

>    
>    > 	#define PTRTOINT64(foo) ((u_int64_t)(long)(foo))
>    
>    That's not.
> 
> 
> right.  one should always use unsigned long in these case.  adding
> a (u_long) fixes *many* warnings :-)

uintptr_t? :)

Anyways, how much is this a problem in the real world?  The program at
the end when run on i386 and pmax gives:

	a = (int64_t)(intptr_t)-1    = 0xffffffffffffffff
	b = (u_int64_t)(intptr_t)-1  = 0xffffffffffffffff
	c = (int64_t)(uintptr_t)-1   = 0xffffffff
	d = (u_int64_t)(uintptr_t)-1 = 0xffffffff
	(void *)(intptr_t)a          = 0xffffffff
	(void *)(intptr_t)b          = 0xffffffff
	(void *)(intptr_t)c          = 0xffffffff
	(void *)(intptr_t)d          = 0xffffffff
	(void *)(uintptr_t)a         = 0xffffffff
	(void *)(uintptr_t)b         = 0xffffffff
	(void *)(uintptr_t)c         = 0xffffffff
	(void *)(uintptr_t)d         = 0xffffffff

and on alpha give:

	a = (int64_t)(intptr_t)-1    = 0xffffffffffffffff
	b = (u_int64_t)(intptr_t)-1  = 0xffffffffffffffff
	c = (int64_t)(uintptr_t)-1   = 0xffffffffffffffff
	d = (u_int64_t)(uintptr_t)-1 = 0xffffffffffffffff
	(void *)(intptr_t)a          = 0xffffffffffffffff
	(void *)(intptr_t)b          = 0xffffffffffffffff
	(void *)(intptr_t)c          = 0xffffffffffffffff
	(void *)(intptr_t)d          = 0xffffffffffffffff
	(void *)(uintptr_t)a         = 0xffffffffffffffff
	(void *)(uintptr_t)b         = 0xffffffffffffffff
	(void *)(uintptr_t)c         = 0xffffffffffffffff
	(void *)(uintptr_t)d         = 0xffffffffffffffff

So for these platforms at least we can cast any long to any int64 and
get away with it.  Can you (or Eric) provide results on sparc, sparc64
and sparc64/compat32?

Simon.
--
#include <stdio.h>
#include <sys/param.h>
#include <sys/types.h>

int
main()
{
	u_int64_t a, b, c, d;
	void *ap, *bp, *cp, *dp;

	a = (int64_t)(intptr_t)-1;
	b = (u_int64_t)(intptr_t)-1;
	c = (int64_t)(uintptr_t)-1;
	d = (u_int64_t)(uintptr_t)-1;

	printf("a = (int64_t)(intptr_t)-1    = %#llx\n", a);
	printf("b = (u_int64_t)(intptr_t)-1  = %#llx\n", b);
	printf("c = (int64_t)(uintptr_t)-1   = %#llx\n", c);
	printf("d = (u_int64_t)(uintptr_t)-1 = %#llx\n", d);

	ap = (void *)(intptr_t)a;
	bp = (void *)(intptr_t)b;
	cp = (void *)(intptr_t)c;
	dp = (void *)(intptr_t)d;

	printf("(void *)(intptr_t)a          = %p\n", ap);
	printf("(void *)(intptr_t)b          = %p\n", bp);
	printf("(void *)(intptr_t)c          = %p\n", cp);
	printf("(void *)(intptr_t)d          = %p\n", dp);

	ap = (void *)(uintptr_t)a;
	bp = (void *)(uintptr_t)b;
	cp = (void *)(uintptr_t)c;
	dp = (void *)(uintptr_t)d;

	printf("(void *)(uintptr_t)a         = %p\n", ap);
	printf("(void *)(uintptr_t)b         = %p\n", bp);
	printf("(void *)(uintptr_t)c         = %p\n", cp);
	printf("(void *)(uintptr_t)d         = %p\n", dp);

	exit(0);
}