PL/I

PL/I

PL/I

 View Only
  • 1.  Calculating number of array elements

    Posted Tue June 25, 2013 02:38 PM

    I'm trying to represent a data structure that consists of a header followed by a number of array elements.  I'd like the number of array elements to be as large as possible while not exceeding 4096 (including the header).  Is it possible to use the SIZE() function for this?  I'm getting message IBM1748I S, "Extents of automatic variables must not depend on the extents of automatic variables declared later in the same block."  My declaration is al follws:

        Dcl
           1 top1 Structure ,
              2 mid1,
                 3 low1 Unsigned Bin Fixed (32),
                 3 low2 Char (8),
              2 mid2 ((4096 - size(mid1)) / size(mid2)),
                 3 low3 Unsigned Bin Fixed (64),
                 3 low4 Char (48);

    It appears to me that the size of mid2 should be able to be calculated first and then used in the calculation for the number of array elements.  Any ideas?

    - mb

    markboonie


  • 2.  Re: Calculating number of array elements

    Posted Tue June 25, 2013 04:00 PM

    mid2 is an array, so you can't use it to define it's own size... but I think it goes further than that, as being a structure member the size can't really be determined until after all the alignment has been taken care of.  But size(mid2(1)) doesn't work either, I suspect because the compiler isn't as devious as humans.

    Anyway, this sort of thing works:

    dcl                                                          
    1   aMid1,                                                   
             3 low3 Unsigned Bin Fixed (32),                     
             3 low4 Char (8);                                    
    dcl                                                          
    1   aMid2,                                                   
             3 low3 Unsigned Bin Fixed (64),                     
             3 low4 Char (48);                                   
                                                                 
    Dcl                                                          
       1 top1 Structure ,                                        
          2 mid1 like aMid1,                                     
          2 mid2 ((4096 - size(aMid1)) / size(aMid2)) like aMid2;

    Possibly there are other variants.

     

    brataj


  • 3.  Re: Calculating number of array elements

    Posted Tue June 25, 2013 04:01 PM

    I see the new and improved communities apparently count posts by community...

    brataj


  • 4.  Re: Calculating number of array elements

    Posted Wed June 26, 2013 09:07 AM

    Interesting.  I would have thought that mid2 was the name not of the array but of the individual element(s) of which the array is composed.  That would explain the error message -- the code is trying to use the SIZE() of the array to define the array itself.  (The meaning of the message is still cryptic to me.  I'll go back now and try to decipher it.)

    Thanks for the bypass, though.  It's more logical, too -- define the smaller structures first, and then define the larger structures as compositions of the smaller ones.

    - mb

    markboonie


  • 5.  Re: Calculating number of array elements

    Posted Wed June 26, 2013 09:35 AM

    Both the dimension(s) and type are bound to a name...

    "declared later in the same block" is I believe applicable in this case because the compiler hasn't yet "committed" to some or all of the structure that you're in the process of defining, so it presumes a later definition is intended.

    Bernie

     

    brataj


  • 6.  Re: Calculating number of array elements

    Posted Thu June 27, 2013 04:34 AM

    It's necessary to specify the number of elements for the array.

    Normally this is specified as a constant (e.g., declare x(25) float; )

    or as a variable whose value is read in or computed

    (e.g., get (m); begin; declare x(m) float; ... )

    Robin400


  • 7.  Re: Calculating number of array elements

    Posted Tue December 02, 2014 10:54 AM

    Further to the explanation of the error message:- the expression

    (4096 - size(mid1)) / size(mid2)

    as part of the declaration of the array

    mid2 ((4096 - size(mid1)) / size(mid2))

    requires the size of <mid2> which isn't known at the time that

    the expression is evaluated.

    Robin400