tunsafeaddr.nim 455 B

1234567891011121314151617181920212223242526272829
  1. discard """
  2. output: '''12'''
  3. """
  4. {.emit: """
  5. NI sum(NI* a, NI len) {
  6. NI i, result = 0;
  7. for (i = 0; i < len; ++i) result += a[i];
  8. return result;
  9. }
  10. """.}
  11. proc sum(a: ptr int; len: int): int {.importc, nodecl.}
  12. proc main =
  13. let foo = [8, 3, 1]
  14. echo sum(unsafeAddr foo[0], foo.len)
  15. # bug #3736
  16. proc p(x: seq[int]) = discard x[0].unsafeAddr # works
  17. proc q(x: seq[SomeInteger]) = discard x[0].unsafeAddr # doesn't work
  18. p(@[1])
  19. q(@[1])
  20. main()