| 1 | (* PTR(s) where the report leaves the address to the implementation: |
| 2 | an empty slice cut from another keeps its place there, and a string |
| 3 | constant, even "", has a place in read-only data. A slice kept in |
| 4 | registers in a loop gives its pointer's register. *) |
| 5 | module PtrPlaces; |
| 6 | import Out; |
| 7 | import SYSTEM; |
| 8 | |
| 9 | proc main*; |
| 10 | var a: [4]U8; s, e: []U8; p: ^U8; i, n: INT; |
| 11 | begin |
| 12 | a := [1, 2, 3, 4]; |
| 13 | s := a[0..4]; |
| 14 | e := s[2..2]; |
| 15 | if SYSTEM.PTR(e) = SYSTEM.PTR(s) + 2 then Out.str("cut empty: at its place\n"); end; |
| 16 | p := SYSTEM.PTR(""); |
| 17 | if p # nil then Out.str("\"\": not nil\n"); end; |
| 18 | n := 0; |
| 19 | for i := 0 to 3 do s := a[i..4]; n := n + INT(SYSTEM.PTR(s) - SYSTEM.PTR(a)); end; |
| 20 | Out.int(n); Out.str("\n"); |
| 21 | end; |
| 22 | |
| 23 | end PtrPlaces. |