Last active
September 10, 2020 16:47
-
-
Save def-/2ed28c3be686fb02fa2d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template offset(Typ, member): int {.immediate.} = | |
var dummy: Typ | |
cast[int](dummy.member.addr) -% cast[int](dummy.addr) | |
type Foo = object | |
x: int | |
y: int | |
echo offset(Foo, y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
a more correct and updated way of doing it would be this:
(i changed the argument name because i liked it more, the other one are fine too)