Path: utzoo!utgpu!attcan!uunet!lll-winken!ames!apple!rutgers!uwvax!tank!uxc!uxc.cso.uiuc.edu!ux1.cso.uiuc.edu!phil From: phil@ux1.cso.uiuc.edu Newsgroups: comp.lang.c Subject: Re: When is a cast not a cast? Message-ID: <6200006@ux1.cso.uiuc.edu> Date: 24 May 89 17:15:00 GMT References: <2747@buengc.BU.EDU> Lines: 34 Nf-ID: #R:buengc.BU.EDU:2747:ux1.cso.uiuc.edu:6200006:000:1079 Nf-From: ux1.cso.uiuc.edu!phil May 24 12:15:00 1989 What about: long x,y,z,*q,*p,a[19]; int i; . . p = a; q = NULL[i]; /* or even i[NULL] */ x = *(p+q); q = q[1]; y = p[q]; q = q[1]; z = q[p]; Obviously this is machine dependent. But it might be useful on most machines anyway since most implement NULL as 0. Thus "q" will be of type pointer, but will in fact have an OFFSET instead of an absolute value. When I program in assembler, I usually index with offsets instead of with integers, so I can avoid the repeated multiplies each time around the loop that increments the offset or integer. Thus: q = q[1]; might be faster depending on how well the compiler recognizes the usage of the constant. By generating code that directly adds the length of a "long" to the value of "q", you avoid all the multiplies. Alternatively in many cases, one can just increment absolute pointers as well. There are a few cases where the same offset can be used in more than one array because the arrays have elements of the same length/type. --Phil howard--