Each record type is rounded up to a multiple of 4 bytes, and this padded size is used as the basis for extensions of the type. In the attached example, moving the kind field of the spatial and temporal types into the shared parent address results in a change in the record layout for spatial, with two byes of padding between the kind and planet fields. The layout of the temporal type is unaffected.
This is a valid translation of the source code, but it's a shame when it makes it more difficult to match the network address layouts that are used for Unix system calls. Consider revising the size calculation for record types so that the alignment is the max of the field alignments, and the total size is rounded up to a multiple of the alignment.
MODULE Bind;
IMPORT Out;
TYPE address = RECORD END;
spatial = RECORD (address) kind: SHORTINT; planet: ARRAY 14 OF CHAR END;
temporal = RECORD (address) kind: SHORTINT; year: INTEGER END;
CONST SPACE = 1; TIME = 2;
PROCEDURE mybind(sockfd: INTEGER; addr: address; len: INTEGER): INTEGER
IS "mybind";
VAR rs: spatial; rt: temporal; x: INTEGER;
BEGIN
rs.kind := SPACE; rs.planet := "Fooey";
rt.kind := TIME; rt.year := 1776;
x := mybind(17, rs, 42);
Out.String("The result was "); Out.Int(x, 0); Out.Ln;
x := mybind(17, rt, 42);
Out.String("The result was "); Out.Int(x, 0); Out.Ln
END Bind.
Each record type is rounded up to a multiple of 4 bytes, and this padded size is used as the basis for extensions of the type. In the attached example, moving the
kind
field of thespatial
andtemporal
types into the shared parentaddress
results in a change in the record layout forspatial
, with two byes of padding between thekind
andplanet
fields. The layout of thetemporal
type is unaffected.This is a valid translation of the source code, but it's a shame when it makes it more difficult to match the network address layouts that are used for Unix system calls. Consider revising the size calculation for record types so that the alignment is the max of the field alignments, and the total size is rounded up to a multiple of the alignment.