Is this portable?

Gregory Kemnitz kemnitz at mitisft.Convergent.COM
Wed May 10 12:24:20 AEST 1989


In article <1914 at plx.UUCP>, evan at plx.UUCP (Evan Bigall) writes:
. This works on my machine, but I am curious as to whether it is "officially"
. correct and portable C.  I can think of some machines where it could be trouble
. 
. 	main()
. 	  { int array[10], *ptr, j;
. 
. 	    for(j=0; j<10; j++)
. 	      array[j]=j;
. 
. 	    ptr= &array[1];
. 
. 	    for(j= -1; j<9; j++)
. 		printf("%d\n", ptr[j]);
. 	  }
.

>From page 94 of K&R:

If pa points to a particular element of an array a, then by definition pa+1
points to the next element, and in general pa-i points i elements before pa
and pa+i points i elements after.

(end of quote).


Greg Kemnitz



More information about the Comp.lang.c mailing list