offsetof() equivalent in PL/I?
Posted: Tue Oct 03, 2017 5:19 am
The SIZE (or STG, or STORAGE) builtin function appears to be the PL/I equivalent of the C sizeof() builtin.
If I have a PL/I structure, such as:
DCL 1 MYSTRUCT,
5 F1 CHAR(13),
5 F2 FIXED BIN(31),
5 F3 FIXED DECIMAL(5,2),
5 F4 FIXED BIN(15),
5 F5 POINTER,
5 F6 CHAR(7);
Is there a way to do the equivalent of the C offsetof(MYSTRUCT,F6) operation for this structure without assuming the value of SIZE() for the POINTER field, nor adding up all the sizes that precede it (along with any alignment padding which may or may not be inserted by the PL/I compiler).
I see there is an OFFSET() builtin associated with AREAs, but that looks like it's a different idea.
I would guess (but haven't tried) that a runtime calculation using POINTERs and FIXED BIN variables of appropriate sizes BASED to those POINTERs could perform this offsetof calculation at runtime, but that seems like a very hard way to do this, if the language even allows it.
If I have a PL/I structure, such as:
DCL 1 MYSTRUCT,
5 F1 CHAR(13),
5 F2 FIXED BIN(31),
5 F3 FIXED DECIMAL(5,2),
5 F4 FIXED BIN(15),
5 F5 POINTER,
5 F6 CHAR(7);
Is there a way to do the equivalent of the C offsetof(MYSTRUCT,F6) operation for this structure without assuming the value of SIZE() for the POINTER field, nor adding up all the sizes that precede it (along with any alignment padding which may or may not be inserted by the PL/I compiler).
I see there is an OFFSET() builtin associated with AREAs, but that looks like it's a different idea.
I would guess (but haven't tried) that a runtime calculation using POINTERs and FIXED BIN variables of appropriate sizes BASED to those POINTERs could perform this offsetof calculation at runtime, but that seems like a very hard way to do this, if the language even allows it.