Robin Vowels <robi...@dodo.com.au> wrote: > > Oon 2025-07-08 00:43, Thomas David Rivers wrote: > > Robin Vowels <robi...@dodo.com.au> wrote: > >> > On 2025-07-07 21:33, Thomas David Rivers wrote: > >> > IBM also evaluates declarations in an order to try and allow some > >> > forward constant declarations > >> > to be used in a previous declaration; but doesn't define what that > >> > order might be - so some forward > >> > declarations work, and some others don't. > >> > >> Such as? > >> > > > > I posted this on the IBM PL/i discussion groups (what follows is > > a synopsis) to demonstrate some issues with declaration order: > > > > Consider this example set of declarations > > > > dcl c1 char(2*size(c2)); > > dcl len fixed bin(31) value(20); > > dcl c2 char(len); > > > > The size of c1 isn't known at the declaration - so c1 is dynamically > > allocated. But - why isn't it known? [IBM's doc says a > > declaration > > with a value clause is a 'restricted expression'.] > > The problem with these declarations is that the variables are > all dynamically allocated. > > > In this similar example: > > > > dcl c3 char(2*size(c4)); > > dcl c4 float bin(70); > > > > the size of c3 is known and it is not dynamically allocated. > > It should be because it is automatic storage, i.e. dynamic. > To avoid dynamic storage, the variable should have the attribute STATIC.
Perhaps I was unclear... In the first situation, the compiler does no treat c1 as having a compile-time known size; and it dynamically allocates the data on the stack at runtime. In the second situation, the compiler treats the size of c3 as having a compile time size. and simply appropriately allocates the space in the frame. Whether it is AUTOMATIC or STATIC doesn't matter in this regard. In fact, if you make the declarations STATIC as in this precise example (you can't make a declaration with a VALUE static as IBM treats it as an unallocated compile-time constant and the compiler complains): ex: proc; dcl c1 char(2*size(c2)) static ; dcl len fixed bin(31) value(20) ; dcl c2 char(len) static ; dcl c3 char(2*size(c4)) static ; dcl c4 float bin(70) static ; end; the IBM compiler will not compile that source. It produces this message: ex.pli(2:2) : IBM1629I S Extents for STATIC variable are not constant. for the declaration of c1. This demonstrates that c3 has a constant compile-time known size, while c1 does not. That was the point of the example... that the definitions are "squishy". While the programmer can change the order of declarations to make this work; this begs the question of what -is- the proper order of declarations. Why does the declaration of c3 work when c1 doesn't? What are the rules that govern this? We can likely discern the rules with adequate experimentation, but the rules are not clearly written down in anything resembling a 'standard' that could be an arbiter of "correctness". And, this also affords the flexibility of changing the rules between revisions, etc... And lastly - this dependence on order wasn't part of the original PL/I standard. - Dave R. - ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN