| 1 |
*> { dg-do run } |
| 2 |
*> { dg-output {000000259(\n|\r\n|\r)} } |
| 3 |
*> { dg-output {0x0000000000000103(\n|\r\n|\r)} } |
| 4 |
*> { dg-output {Faith (\n|\r\n|\r)} } |
| 5 |
*> { dg-output {Hope (\n|\r\n|\r)} } |
| 6 |
*> { dg-output {Charity (\n|\r\n|\r)} } |
| 7 |
*> { dg-output {Pointers are correctly equal (\n|\r\n|\r)} } |
| 8 |
*> { dg-output {Pointers are correctly different(\n|\r\n|\r)} } |
| 9 |
*> { dg-output {Pointers are correctly different(\n|\r\n|\r)} } |
| 10 |
*> { dg-output {Pointers are correctly different(\n|\r\n|\r)} } |
| 11 |
*> { dg-output {Pointers are correctly different(\n|\r\n|\r)} } |
| 12 |
*> { dg-output {Pointers are correctly equal (\n|\r\n|\r)} } |
| 13 |
*> { dg-output {Pointers are correctly equal (\n|\r\n|\r)} } |
| 14 |
*> { dg-output {Pointers are correctly equal (\n|\r\n|\r)} } |
| 15 |
*> { dg-output {NOT EQUAL is correctly FALSE } } |
| 16 |
ID DIVISION. |
| 17 |
PROGRAM-ID. pointers. |
| 18 |
DATA DIVISION. |
| 19 |
WORKING-STORAGE SECTION. |
| 20 |
01 WS-POINTER USAGE IS POINTER . |
| 21 |
01 WS-PVALUE REDEFINES WS-POINTER PIC 9(9) COMP-5. |
| 22 |
01 WS-POINTER2 USAGE IS POINTER . |
| 23 |
01 WS-PVALUE2 REDEFINES WS-POINTER2 PIC 9(9) COMP-5. |
| 24 |
01 VALUE-SOURCE1 PIC X(12). |
| 25 |
01 VALUE-SOURCE2 PIC X(12). |
| 26 |
01 VALUE-SOURCE3 PIC X(12). |
| 27 |
01 VALUE-DEST PIC X(12). |
| 28 |
LINKAGE SECTION. |
| 29 |
01 DEREFERENCER PIC X(12). |
| 30 |
PROCEDURE DIVISION. |
| 31 |
MOVE 259 TO WS-PVALUE |
| 32 |
DISPLAY WS-PVALUE |
| 33 |
DISPLAY WS-POINTER |
| 34 |
*> Pointer manipulation: ADDRESS OF to ADDRESS OF |
| 35 |
MOVE "Faith" TO VALUE-SOURCE1 |
| 36 |
SET ADDRESS OF DEREFERENCER TO ADDRESS OF VALUE-SOURCE1 |
| 37 |
MOVE DEREFERENCER TO VALUE-DEST |
| 38 |
DISPLAY VALUE-DEST |
| 39 |
*> Pointer manipulation: POINTER to ADDRESS OF |
| 40 |
*> ADDRESS OF to POINTER |
| 41 |
MOVE "Hope" TO VALUE-SOURCE2 |
| 42 |
SET WS-POINTER TO ADDRESS OF VALUE-SOURCE2 |
| 43 |
SET ADDRESS OF DEREFERENCER TO WS-POINTER |
| 44 |
DISPLAY DEREFERENCER |
| 45 |
*> Pointer manipulation: Pointer to pointer: |
| 46 |
MOVE "Charity" TO VALUE-SOURCE3 |
| 47 |
SET WS-POINTER2 TO ADDRESS OF VALUE-SOURCE3 |
| 48 |
SET WS-POINTER TO WS-POINTER2 |
| 49 |
SET ADDRESS OF DEREFERENCER TO WS-POINTER |
| 50 |
DISPLAY DEREFERENCER |
| 51 |
IF WS-POINTER EQUAL TO WS-POINTER2 |
| 52 |
DISPLAY "Pointers are correctly equal " |
| 53 |
ELSE |
| 54 |
DISPLAY "Pointers are incorrectly different". |
| 55 |
SET WS-POINTER2 TO ADDRESS OF VALUE-DEST |
| 56 |
IF WS-POINTER EQUAL TO WS-POINTER2 |
| 57 |
DISPLAY "Pointers are incorrectly equal" |
| 58 |
ELSE |
| 59 |
DISPLAY "Pointers are correctly different" |
| 60 |
SET WS-POINTER TO NULL |
| 61 |
IF WS-POINTER EQUAL TO WS-POINTER2 |
| 62 |
DISPLAY "Pointers are incorrectly equal" |
| 63 |
ELSE |
| 64 |
DISPLAY "Pointers are correctly different" |
| 65 |
IF NULL EQUAL TO WS-POINTER2 |
| 66 |
DISPLAY "Pointers are incorrectly equal" |
| 67 |
ELSE |
| 68 |
DISPLAY "Pointers are correctly different" |
| 69 |
IF WS-POINTER2 EQUAL TO NULL |
| 70 |
DISPLAY "Pointers are incorrectly equal" |
| 71 |
ELSE |
| 72 |
DISPLAY "Pointers are correctly different" |
| 73 |
SET WS-POINTER2 TO NULL |
| 74 |
IF WS-POINTER EQUAL TO WS-POINTER2 |
| 75 |
DISPLAY "Pointers are correctly equal " |
| 76 |
ELSE |
| 77 |
DISPLAY "Pointers are incorrectly different". |
| 78 |
IF WS-POINTER EQUAL TO NULL |
| 79 |
DISPLAY "Pointers are correctly equal " |
| 80 |
ELSE |
| 81 |
DISPLAY "Pointers are incorrectly different". |
| 82 |
IF WS-POINTER EQUAL TO NULL |
| 83 |
DISPLAY "Pointers are correctly equal " |
| 84 |
ELSE |
| 85 |
DISPLAY "Pointers are incorrectly different". |
| 86 |
PERFORM one-last-dance |
| 87 |
STOP RUN. |
| 88 |
one-last-dance. |
| 89 |
IF WS-POINTER NOT EQUAL TO NULL |
| 90 |
*>Making sure comments don't cause trouble |
| 91 |
DISPLAY "Pointers are incorrectly EQUAL " |
| 92 |
ELSE |
| 93 |
*>Making sure comments don't cause trouble |
| 94 |
DISPLAY "NOT EQUAL is correctly FALSE " |
| 95 |
END-IF. |
| 96 |
one-last-dance-end. |
| 97 |
DISPLAY "We should never get here". |
| 98 |
END PROGRAM pointers. |