1

关于结构化文本编程语言:

如果我有一个指向表的指针:

crcTable : ARRAY [0..255] OF WORD;
pcrcTable : POINTER TO WORD;
pcrcTable := ADR(crcTable);

我想取消引用某个索引处的表,这样做的语法是什么?我认为等效的 C 代码将是:

unsigned short crcTable[256];
unsigned short* pcrcTable = &crcTable[0];
dereferencedVal = pcrcTable[50]; //Grab table value at index = 50
4

1 回答 1

2

您需要首先根据要到达的数组索引移动指针。然后进行解引用。

// Dereference index 0 (address of array)
pcrcTable := ADR(crcTable);
crcVal1 := pcrcTable^;

// Dereference index 3 (address of array and some pointer arithmetic)
pcrcTable := ADR(crcTable) + 3 * SIZEOF(pcrcTable^);
crcVal2 := pcrcTable^;

// Dereference next index (pointer arithmetic)
pcrcTable := pcrcTable + SIZEOF(pcrcTable^);
crcVal3 := pcrcTable^;
于 2017-06-20T06:29:17.100 回答