You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
procfoo(arg: int) =var g {.global.} = arg +1echo g
foo(123)
produces
Error: execution of an external compiler program 'gcc -c -w -I'~/.choosenim/toolchains/nim-#devel/lib' -o ~/.cache/nim/bug_d/bug.c.o ~/.cache/nim/bug_d/bug.c' failed with exit code: 1
~/.cache/nim/bug_d/bug.c: In function 'NimMainModule':
~/.cache/nim/bug_d/bug.c:168:41: error: 'arg' undeclared (first use in this function)
TM_rmH9bpP9b3ZIjFP4QhigizlA_2 = addInt(arg, ((NI) 1));
^~~
~/.cache/nim/bug_d/bug.c:168:41: note: each undeclared identifier is reported only once for each function it appears in
The text was updated successfully, but these errors were encountered:
If I understand this correctly, you want g to be initialized on the first call only, so you'd have to do this:
procfoo(arg: int) =var g {.global.} =0
once:
g = arg +1echo g
This is because {.global.}s are initialized during program startup, which of course, arg wouldn't be available then since it only exists within the proc.
The compiler should raise a proper error for this case however.
compiling
produces
The text was updated successfully, but these errors were encountered: