Supported RPG Features

A data structure may hold a POINTER subfield, in both free-format (DCL-DS) and fixed-format D-specs (column 40 = *). Reading it, writing it, assigning *NULL and comparing against *NULL all work, including through a BASED data structure - which is what makes the linked-list idiom available:

DCL-S head POINTER;
DCL-S cur POINTER;
DCL-DS node QUALIFIED BASED(cur);
  val PACKED(5:0);
  nxt POINTER;
END-DS;

cur = head;
DOW cur <> *NULL;
  // ... use node.val ...
  cur = node.nxt;
ENDDO;

A pointer occupies 16 bytes and starts on a 16-byte boundary, as it does on IBM i. That alignment inserts padding before the pointer, and the padding counts toward %SIZE:

DCL-DS d QUALIFIED;
  a CHAR(1);     // offset 0
  p POINTER;     // offset 16 - 15 bytes of padding precede it
  b CHAR(1);     // offset 32
END-DS;          // %SIZE(d) = 33

The structure is padded to a pointer, never rounded up after one: the example above is 33 bytes, not 48. Only pointers carry an alignment requirement - every other subfield stays packed against its predecessor.

The requirement reaches through a LIKEDS subfield. A nested structure whose template holds a pointer at any depth starts on a 16-byte boundary itself, so that each of its pointers lands aligned - and for a DIM(n) subfield that applies to every element, since the element width is a multiple of 16:

DCL-DS Elem_T QUALIFIED TEMPLATE;
  name CHAR(10);   // offset 0
  ptr POINTER;     // offset 16
END-DS;            // %SIZE(Elem_T) = 32

DCL-DS d QUALIFIED;
  num INT(10);              // offset 0
  field LIKEDS(Elem_T) DIM(3);  // offset 16 - 12 bytes of padding precede it
END-DS;                     // %SIZE(d) = 112

A template that holds no pointer is packed as before, so the same shape with len INT(10) in place of ptr puts field at offset 4 and sizes 46. The padding follows from the pointer, not from the nesting.

This does not depend on the ALIGN keyword. ALIGN governs the alignment of integer, unsigned and float subfields; pointer alignment applies whether or not the structure declares it.

Two limits are worth stating: