交错阵列 PL1 (PL/I)

Jagged array PL1 (PL/I)

我需要 PL/I 中的锯齿状动态数组,但我不知道如何实现它。 需要这样的东西:

dcl v dim(*,*) fixed bin(31) ctl;
allocate v dim(5,*);             
allocate v(1) dim(10);           
allocate v(2) dim(100);    

我该怎么做?

数组声明中的星号仅在子例程中使用,表示数组维度将从参数中传递的数组元数据中获取。

为了控制通过allocate语句分配的数组的大小,使用变量:

dcl v dim(d1, d2) ctl, 
   d1 fixed bin(31), 
   d2 fixed bin(31); 

 d1 = 5; 
 d2 = 15; 
 alloc v;

这会给你 v(5, 15)

您可以为下限和上限使用变量:

dcl w dim(l1:u1, l2:u2) ctl, 
   l1 fixed bin(31), 
   l2 fixed bin(31),
   u1 fixed bin(31), 
   u2 fixed bin(31); 

 get data(l1, u1, l2, u2);
 alloc w;

使用 l1=-4; u1=6; l2=15; u2=144; 的 SYSIN 输入,w 被分配为 w(-4:6, 15:144)

对于 IBM PL/I,请参阅 V5.1 语言参考 手册部分 Controlled storage and attribute,或当前 PDF 的第 260 页(实际第 296 页)文档.

我按照piet.t所说的方式解决了这个问题。已创建指针数组并为每个指针分配数组。恕我直言,这看起来不太方便。

    mainp:procedure options(main);                                 

    dcl n fixed bin(31);                                           
    dcl pp ptr;                                                    
    dcl 1 pointers based(pp),                                      
          2 length fixed bin(31),                                  
          2 at dim(n refer (length)) ptr;                          

    dcl m fixed bin(31);                                           
    dcl 1 values based,                                            
          2 length fixed bin(31),                                  
          2 at dim(m refer (length)) fixed bin(31);                

    n=2;                                                           
    allocate pointers;                                             
    m=2;                                                           
    allocate values set(pointers.at(1));                           
    m=4;                                                           
    allocate values set(pointers.at(2));                           

    pointers.at(1)->values.at(1)=1;                                
    pointers.at(1)->values.at(2)=2;                                
    pointers.at(2)->values.at(1)=10;                               
    pointers.at(2)->values.at(2)=20;                               
    pointers.at(2)->values.at(3)=30;                               
    pointers.at(2)->values.at(4)=40;                               

    put skip list("Line 1 length: ",pointers.at(1)->values.length);
    put skip list("Line 2 lenght: ",pointers.at(2)->values.length);
    put skip list('');                                             
    put skip list(pointers.at(1)->values.at(1),                    
                  pointers.at(1)->values.at(1));                   

    put skip list(pointers.at(2)->values.at(1),                    
                  pointers.at(2)->values.at(2),                    
                  pointers.at(2)->values.at(3),
              pointers.at(2)->values.at(4));                               
end;