From: Dan <morrildl@nycap.rr.com>
To: axp-list@redhat.com
Subject: Re[2]: So Y is my pointer so bogus
Date: Wed, 3 Feb 1999 18:40:00 -0500 (EST) [thread overview]
Message-ID: <199902032340.SAA25536@mail-atm.nycap.rr.com> (raw)
In-Reply-To: <Pine.LNX.4.04.9902031756480.6536-100000@sdi.aatech.com>
[-- Attachment #1: Body --]
[-- Type: text/plain, Size: 1432 bytes --]
According to the gods of SMTP, Jason Duerstock wrote:
> Unless my brain has turned to jello lately,
Hmm... sounds like me, lately. :)
> a = (int *) a;
> dereferences null, thus causing your program to go kerfloom.
Actually, (int *)a isn't dereferencing a, it's typecasting it.
> > 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;
Hmm. This should be equivalent to:
a = 0 + -20 * 1 + -5 * 348.
That should be a = -1760, assuming the type promotion that's going on there is
working as expected.
sizeof( int* ) should be 8, whereas sizeof( unsigned int ) should be 4. I
can't remember the promotion rules for C (and I'm not sure I ever knew them for
pointers :) but are the unsigned ints getting promoted to int*, or is the int*
getting demoted to 32 bits? Or, even worse, is nothing happening at all, and
bits are being lost during the operation?
Perhaps you could try:
a = (int *)a +(int *)((x2-x1-x3)*P) + (int*)((y2-y1-y3)*S);
..to force the unsigned ints to get promoted. Alternatively try declaring P
and S as unsigned long ints, or as int* ?
Dan Morrill
Computer Scientist, Physicist
If I'm talking out of my arse, please excuse me. :)
next prev parent reply other threads:[~1999-02-03 23:47 UTC|newest]
Thread overview: 10+ 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 ` Dan [this message]
1999-02-04 0:38 ` Michal Jaegermann
1999-02-04 11:25 ` Phil Carmody
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