Supported RPG Features

A pointer may be displaced by a numeric offset, and two pointers may be subtracted to obtain the offset between them. Both forms work in free-format expressions and in fixed-format C-spec expressions.

DCL-DS Buf QUALIFIED;
  All CHAR(10);
END-DS;
DCL-S p1 POINTER;
DCL-S p2 POINTER;
DCL-S ch CHAR(1) BASED(p2);
DCL-S diff INT(10);

Buf.All = 'abcdefghij';
p1 = %ADDR(Buf.All);
p2 = p1 + 8;      // ch is now 'i'
p2 = p2 - 1;      // ch is now 'h'
diff = p2 - p1;   // 7

Two rules are worth stating explicitly:

Adding two pointers together is meaningless and is rejected at compile time.