关于结构化文本编程语言:
如果我有一个指向表的指针:
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
答案 0 :(得分: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^;