0

我不明白源代码 PL/I:

      DCL AA CHAR(10)   BASED(P1);
      DCL BB CHAR(10)  INIT ("BBBBBBBBBB");
      DCL CC CHAR(10)  INIT ("CCCCCCCCCC");
      DCL DD CHAR(10)  INIT ("DDDDDDDDDDD");
      DCL ADDR BUILTIN;
      DCL P1 PTR;
      DCL P2 PTR;

        P1 = ADDR(BB);
        Display(AA);

        P1 = ADDR(P2);
        Display(AA);

        P2 = ADDR(DD);
        Display(AA);

帮助我理解显示变量 AA。非常感谢

4

1 回答 1

2

in my humble opinion it goes like this;

Let's agree that variable AA represents 10 bytes of storage beginning the pointer address of P1 in the DSA

Statement P1 = ADDR(BB); makes P1 point at the address of BB, then Display(AA); will show the 10 character bytes equal to BB

Statement P1 = ADDR(P2); makes the P1 point at another address in the DSA, namely where the variable P2 is situated. Thus the display-statement shows 10 bytes of storage, whereof the 4 bytes equals the address of... well nothing predictible yet, as the pointer P2 is not yet initialized

Statement P2 = ADDR(DD); moves the address of DD to P2, and the following dispaly statement gives the address of DD in the foremost 4 bytes, and the following 6 bytes are just what happens to be the next in DSA - however these very 6 bytes remains the same as before

于 2015-05-03T15:52:35.207 回答