Robin Vowels <[email protected]> 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'.]

   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.

The response from IBM was... (abbreviated):

   If the order of the declares is such that the size of a variable
   does not depend on the size of variables declared after it, then
   a dynamic allocation would not occur (so, for example, if c1 came
   after c2 in the first example, there would be no dynamic allocation.
   But as you note, even in some cases where the declares are not in
   that order, there will be no dynamic allocation. For example, in
   your second example, the size of c4 doesn't depend on anything
   before it, and so c3's size is easily figured out. There is some
   code in the compiler that attempts to reorder declares and
   effectively moves the declare for c3 after c4. But in the
   c1/c2 example, things appear a little complicated and no
   reordering is done.

This is an example of things IBM has done that are not in agreement
with the standard and that are poorly defined (the standard doesn't
have a "value clause" nor restricted expressions.)  What is the
re-ordering that occurs so that some expressions can be evaluated as
constant? On what is is based?  What is the definition of "a little
complicated"?  We can make educated guesses at these, but that's all
they are, and certainly not codified in a "standard" (nor even
mentioned in IBM's documentation.)

If we were adhering to a standard, these things would be spelled
out instead of leaving it to programmatic experimentation.

Of course, the PL/I standard has not been updated in many decades,
leaving a language implementor in an uneviable position regarding
new language features, etc... Unfortunately, I believe while IBM
continues to evolve the language, they don't clearly spell out those
changes... leaving us with an "it is what it is" definition.

        - Dave R. -

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to