proc gimme(): cstring {.exportc.} =
result = "Hey there C code! " & $rand(100)
Run
is broken. Here is a sketch of a solution:
proc gimme(): cstring {.exportc.} =
let tmp = "Hey there C code! " & $rand(100)
result = cast[cstring](malloc(tmp.len + 1))
copyMem(result, tmp, tmp.len + 1)
# C caller must call `free`
Run
Your code sort of used to work with older GCs as you noticed but it doesn't
work with ORC anymore.
If you can avoid having your `main` in C, do so immediately. And then throw the
rest of the C code away too. ;-)