tuncheckedarray.nim 437 B

1234567891011121314151617181920
  1. discard """
  2. exitcode: 0
  3. targets: "c cpp"
  4. """
  5. proc main =
  6. block: # issue 19171
  7. var a = ['A']
  8. proc mutB(x: var openArray[char]) =
  9. x[0] = 'B'
  10. mutB(toOpenArray(cast[ptr UncheckedArray[char]](addr a), 0, 0))
  11. doAssert a[0] == 'B'
  12. proc mutC(x: var openArray[char]; c: char) =
  13. x[0] = c
  14. let p = cast[ptr UncheckedArray[char]](addr a)
  15. mutC(toOpenArray(p, 0, 0), 'C')
  16. doAssert p[0] == 'C'
  17. main()