/* test107.c
   L. Stewart February 15, 1982  5:00 PM
   test for pointer arithmetic */

struct ZN {
  struct ZN *next;
  int length;
  };

struct twowords {
  int a, b;
  };

struct threewords {
  int a, b, c;
  };

struct ZN *z, *root, az[5];
int i;
struct twowords *p2, *q2;
struct threewords *p3, *q3;

main()
  {
  /* multiple assignment */
  root = z = az;
  for (i=0;i<4;i+=1) {
    z->next = z+i;
    z->next = &z[i];
    z->length = i;
    z+=1;
    };
  /* try adding i*2 to the cell p3 */
  p3 = (struct threewords *) (((int *) p3)+i);
  /* this one breaks */
  q2 = (struct twowords *) (p3+i);
  /* does this one work better? */
  q2 = (struct twowords *) (((struct threewords *) p3)+i);
  /* how about */
  q3 = p3+i;
  q2 = (struct twowords *) q3;
  /* this one breaks */
  q2 = (struct twowords *) (p3-i);
  /* does this one work better? */
  q2 = (struct twowords *) (((struct threewords *) p3)-i);
  /* how about */
  /* try subtraction */
  q3 = p3-i;
  q2 = (struct twowords *) q3;
  /* test do .. while loop */
  do {
    i += 1;
    } while (i<0);
  };