如何在PL1编程语言中使用指针
我正在尝试学习 PL1 中指针的使用。然而,以下方法不起作用
DCL MYPTR PTR;
DCL MYVAR CHAR(10) INIT('1234567890');
PUT SKIP(2) LIST('DISPLAY MYVAR: ',MYVAR);
MYPTR = ADDR(MYVAR);
PUT SKIP(2) LIST('DISPLAY MYPTR: ',MYPTR);
输出:
DISPLAY MYVAR: 1234567890
DISPLAY MYPTR:
I am trying to learn the use of pointers in PL1. However below approach is not working
DCL MYPTR PTR;
DCL MYVAR CHAR(10) INIT('1234567890');
PUT SKIP(2) LIST('DISPLAY MYVAR: ',MYVAR);
MYPTR = ADDR(MYVAR);
PUT SKIP(2) LIST('DISPLAY MYPTR: ',MYPTR);
OUTPUT:
DISPLAY MYVAR: 1234567890
DISPLAY MYPTR:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
指针是包含存储地址的变量。您可以使用它们来重新映射具有不同布局的存储区域。例如,假设单个数据集中有具有不同布局的记录,例如:
这些声明预留两个不同的存储区域,每个类型一个。请注意,记录具有不同的长度。如果您只知道类型以及读取记录后的长度,您将如何读取记录?您需要执行以下操作:
。这涉及到许多不必要的数据移动。
使用指针以及声明中关联的
based()
属性,您可以将结构定义为映射,即无需底层存储。然后,您可以对所有映射使用单个指针。现在,您执行如下操作:
RecordType1.Field01
或RecordType2.Number02
不再有不必要的数据从输入区域移动到映射区域。
如果您读取记录从数据集中,您甚至可以避免第一次移动并直接访问输入缓冲区中的记录;只需告诉读取语句设置指针,而不是将数据移至 LongestRecord 字段:
您现在可以删除 LongestRecord 变量的声明,并将语句设置 < code>pRecord 到该变量的地址。
为了完整起见:PL/I 提供了另一种方法来映射具有两个或多个不同布局的存储区域:
UNION
,但这不是这里的问题。Pointers are variables that contain a storage address. You use them to remap a storage area with different layout. For example, assume you've got records in a single data set that have different layout, say:
These declarations set aside two distinct storage areas, one for each type. Note that the records have different lengths. How would you read in the records, if you only know the type, and with this the length after having read the record? You would need to do something like:
This involves a lot of unnecessary data moves.
Using pointers, and the associated
based()
attribute in declarations, you can define the structures as mapping, i.e. witout underlying storage. You then use a single pointer for all mappings.Now, you do something like this:
LongestRecord
field,RecType
(assuming the type indicator is at the same position for each type).RecordType1.Field01
, orRecordType2.Number02
No more unnecessary data moves from input area to mapping area..
If you read the records from a data set, you can even avoid the first move and access the records directly in the input buffer; just tell the read statement to set the pointer, instead of moving the data into the
LongestRecord
field:You can now drop the declaration for the
LongestRecord
variable, and the statement settingpRecord
to the address of that variable.For completeness, only: PL/I offers another way to map a storage area with two or more different layouts:
UNION
, but this is not the question here.