offsetof() equivalent in PL/I?

HLASM for MVS. PL/I for MVS & Enterprise PL/I for z/OS.
Previous topicNext topic

Topic author
peeterjoot
Registered Member
Posts: 15
Joined: Fri Mar 03, 2017 2:01 am

offsetof() equivalent in PL/I?

Post by peeterjoot » 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.



User avatar

Akatsukami
Global Moderator
Global Moderator
Posts: 110
Joined: Tue Oct 20, 2015 3:20 am
Location: Bloomington, IL

Re: offsetof() equivalent in PL/I?

Post by Akatsukami » Tue Oct 03, 2017 6:37 pm

It's been a couple of decades since I wrote any C, so I may not properly understand what you're looking for, but I think you want the LOCATION function.


"I come to the conclusion that, men loving according to their own will and fearing according to that of the prince, a wise prince should establish himself on that which is in his own control and not in that of others." -- Niccolò Machiavelli

User avatar

prino
Registered Member
Posts: 54
Joined: Sun Jun 01, 2014 4:15 am
Location: Oostende, Belgium

Re: offsetof() equivalent in PL/I?

Post by prino » Tue Oct 03, 2017 9:44 pm

offset = addr(mystruct.f6) - addr(mystruct.f1);


Robert AH Prins
robertahprins @ the.17+Gb.Google thingy


Topic author
peeterjoot
Registered Member
Posts: 15
Joined: Fri Mar 03, 2017 2:01 am

Re: offsetof() equivalent in PL/I?

Post by peeterjoot » Thu Oct 05, 2017 4:02 pm

Akatsukami wrote:
Tue Oct 03, 2017 6:37 pm
It's been a couple of decades since I wrote any C, so I may not properly understand what you're looking for, but I think you want the LOCATION function.
Thank you, that looks like the PL/I equivalent to C's offsetof().



Previous topicNext topic

Return to “Assembler & PL/I.”