about summary refs log blame commit diff stats
path: root/src/utils/myaddr.nim
blob: 4405e0c4d2aec0753f981d5141b84bb806f8e199 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

















                                                                      
# Before 2.0, `addr' only worked on mutable types, and `unsafeAddr'
# was needed to take the address of immutable ones.
#
# This was changed in 2.0 for some incomprehensible reason, so now to
# write code that compiles on both versions you have to take care that
# you use the right overload without compiler help.
#
# This module fixes the above problem; it is automatically included
# in every file by nim.cfg.

when NimMajor >= 2:
  const msg = "expression has no address; maybe use `unsafeAddr'"

  template addr(x: untyped): untyped {.used, error: msg.} =
    discard

  template addr(x: var untyped): untyped {.used.} =
    system.addr x