From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (qmail 17194 invoked from network); 3 Feb 1999 23:47:20 -0000 Received: from mail.redhat.com (199.183.24.239) by lists.redhat.com with SMTP; 3 Feb 1999 23:47:20 -0000 Received: from mail-atm.nycap.rr.com (root@mail-atm.nycap.rr.com [24.92.32.1]) by mail.redhat.com (8.8.7/8.8.7) with ESMTP id SAA14578 for ; Wed, 3 Feb 1999 18:40:03 -0500 Received: from nycap.rr.com (toshiba-179-24.nycap.rr.com [204.210.179.24]) by mail-atm.nycap.rr.com (8.9.1/8.9.1) with SMTP id SAA25536 for ; Wed, 3 Feb 1999 18:40:00 -0500 (EST) Date: Wed, 3 Feb 1999 18:40:00 -0500 (EST) From: Dan Message-Id: <199902032340.SAA25536@mail-atm.nycap.rr.com> To: axp-list@redhat.com Subject: Re[2]: So Y is my pointer so bogus In-Reply-To: X-Mailer: Applixware 4.41 (1021.285.30) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; name="Body" Content-Transfer-Encoding: 7bit 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. :)