From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (qmail 23617 invoked from network); 4 Feb 1999 00:46:16 -0000 Received: from mail.redhat.com (199.183.24.239) by lists.redhat.com with SMTP; 4 Feb 1999 00:46:16 -0000 Received: from ellpspace.math.ualberta.ca (michal@ellpspace.math.ualberta.ca [129.128.88.19]) by mail.redhat.com (8.8.7/8.8.7) with ESMTP id TAA18796 for ; Wed, 3 Feb 1999 19:38:57 -0500 Received: (from michal@localhost) by ellpspace.math.ualberta.ca (8.8.8/8.8.8) id RAA18075 for axp-list@redhat.com; Wed, 3 Feb 1999 17:38:55 -0700 From: Michal Jaegermann Message-Id: <199902040038.RAA18075@ellpspace.math.ualberta.ca> Subject: Re: So Y is my pointer so bogus To: axp-list@redhat.com Date: Wed, 3 Feb 1999 17:38:55 -0700 (MST) In-Reply-To: <36B8CF6A.D373F882@voicenet.com> from "Uncle George" at Feb 3, 99 05:36:26 pm Content-Type: text Uncle George wrote: > > This little example caused a (un-expected ) pointer failure in one of > the font routines in my java 1.2 port on linux/alpha. Do you mean that you are getting different results when you will do a = (int *)a +(x2-x1-x3)*P + (y2-y1-y3)*S; and a = (int *)a +((x2-x1-x3)*P + (y2-y1-y3)*S); Ordering and promotion rules got you. :-) > It was expected to > add a -1760 ( -1760 * sizeof(int)) but does not. Eh??? Both P and S are unsigned int. Whatever a result it definitely will be not -1760. > Ugg. what is a 64bitter to do. Exactly what you asked for. :-) Print that way and things will be clear a = (int *)a + (x2-x1-x3)*P; printf("%p %x\n", a, (x2-x1-x3)*P); a = (int *)a + (y2-y1-y3)*S; printf("%p %x\n", a, (y2-y1-y3)*S); If you want signed quantities then do not use unsigned. Stupid tricks with types and their representations will eventually bite your back. BTW: " a = NULL ; printf ("%p\n", (int *)a - 1760); " will print 0xffffffffffffe480. Is this what you really wanted in the first place? Michal > main() > { > > int x1,x2,x3; > int y1,y2,y3; > unsigned int P; > unsigned int S; > void *a; > > a = (void *)0; > x1=20,x2=0,x3=0; > y1=5, y2=0,y3=0; > P = 1; > S = 348; > > a = (int *)a +(x2-x1-x3)*P + (y2-y1-y3)*S; > printf("a = %p\n",a); > }