From: Phil Carmody <carmody@cpd.ntc.nokia.com>
To: axp-list@redhat.com
Subject: Re: So Y is my pointer so bogus
Date: Thu, 04 Feb 1999 11:25:34 +0000 [thread overview]
Message-ID: <36B983AE.54A8BFA0@cpd.ntc.nokia.com> (raw)
In-Reply-To: 36B8CF6A.D373F882@voicenet.com
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. It was expected to
> add a -1760 ( -1760 * sizeof(int)) but does not.
> a = (int *)a +(x2-x1-x3)*P + (y2-y1-y3)*S;
in expressions of the form
int * unsigned
The int gets promoted to the unsigned type.
The value therefore is _not_ -1760, it 0xFFFF~~~~
When promoted to a 64bit type (e.g. (type*)) as it's unsigned it will become 0x00000000FFFF~~~~
and then scaled by sizeof(type)
It's doing exactly what was programmed, the programmer was in error.
If you want the difference between pointers, why not use ptrdiff_t?
That _is_ what it was invented for.
FatPhil
--
Phil Carmody
Not speaking for or on behalf of Nokia Telecommunications.
"At the showing of blue movies at Scotland Yard I take the precaution
of removing my glasses, which reduces the whole messy business to an
impressionist blur." John Mortimer, QC, 1978
next prev parent reply other threads:[~1999-02-04 11:33 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
1999-02-04 11:25 ` Phil Carmody [this message]
-- 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