Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
From: Michal Jaegermann <michal@ellpspace.math.ualberta.ca>
To: axp-list@redhat.com
Subject: Re: So Y is my pointer so bogus
Date: Wed, 3 Feb 1999 17:38:55 -0700 (MST)	[thread overview]
Message-ID: <199902040038.RAA18075@ellpspace.math.ualberta.ca> (raw)
In-Reply-To: <36B8CF6A.D373F882@voicenet.com> from "Uncle George" at Feb 3, 99 05:36:26 pm

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);
> }


  parent reply	other threads:[~1999-02-04  0:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-02-03 22:36 So Y is my pointer so bogus Uncle George
1999-02-03 22:59 ` Jason Duerstock
1999-02-03 23:32   ` B. James Phillippe
1999-02-03 23:45     ` Uncle George
1999-02-04  0:51       ` Michal Jaegermann
1999-02-04  0:55         ` Michal Jaegermann
1999-02-03 23:36   ` Uncle George
1999-02-03 23:40   ` Re[2]: " Dan
1999-02-04  0:38 ` Michal Jaegermann [this message]
1999-02-04 11:25 ` Phil Carmody
  -- strict thread matches above, loose matches on Subject: below --
1999-02-03 22:57 Lagodzinski, Andrew
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox