offsetof() equivalent in PL/I?

HLASM for MVS. PL/I for MVS & Enterprise PL/I for z/OS.
Post Reply
peeterjoot
Registered Member
Posts: 15
Joined: Fri Mar 03, 2017 2:01 am
Contact:

offsetof() equivalent in PL/I?

Post by peeterjoot »

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: 122
Joined: Tue Oct 20, 2015 3:20 am
Location: Bloomington, IL
Contact:

Re: offsetof() equivalent in PL/I?

Post by Akatsukami »

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: 68
Joined: Sun Jun 01, 2014 4:15 am
Location: Vilnius, Lithuania
Contact:

Re: offsetof() equivalent in PL/I?

Post by prino »

offset = addr(mystruct.f6) - addr(mystruct.f1);
Robert AH Prins
robertahprins @ the.17+Gb.Google thingy
Some z/OS code here
peeterjoot
Registered Member
Posts: 15
Joined: Fri Mar 03, 2017 2:01 am
Contact:

Re: offsetof() equivalent in PL/I?

Post by peeterjoot »

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().
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “Assembler & PL/I.”