Nim icon indicating copy to clipboard operation
Nim copied to clipboard

exportc procedures in other procedures can get deleted

Open Menduist opened this issue 2 years ago • 0 comments
trafficstars

Description

proc heya* =
  proc zzz {.exportc.} =
    echo "yey"
    
heya()
proc zzz {.importc.}
zzz()

Nim Version

d73fff1ecc858783a3f1a90830e1bad4a3a23737

Current Output

@mtestb.nim.c:(.text+0x230): undefined reference to `zzz'

Expected Output

Compiles

Possible Solution

My use case is that zzz is generated by a macro, but not a closure, so it can be called from C safely. Cannot add * to prevent deletion by the compiler as this is not a top level procedure

Workaround:

proc heya* =
  proc zzz {.exportc.} =
    echo "yey"
  if false: zzz()
    
heya()
proc zzz {.importc.}
zzz()

Additional Information

No response

Menduist avatar Nov 29 '22 22:11 Menduist