so the main reason is to avoid mangled names when exposing Nim functions (eg
via shared library or static link library) to a C (or C-like) program that
would call Nim code via extern "C"?
eg:
os/mylib.nim:
proc foo1()=discard
proc foo2() {. extern: "nos$1" .} =discard
proc foo2(a:int) {. extern: "nos$1a" .} =discard
Run
util.cpp:
extern "C" void foo1_9c8JPzPvtM9azO6OB23bjc3Q();
extern "C" void nosfoo2();
extern "C" void nosfoo2a(int64_t a);
int main(){
foo1_9c8JPzPvtM9azO6OB23bjc3Q();
return 0;
}
Run
## alternative approach:
* auto-generate prefix using module name (which is assumed unique by Nim
within a project anyways; if not, using fully qualified package/module name
would work)
os/mylib.nim:
proc foo1() # mangle as usual
proc foo2(a:int) {. extern: "nos$1a" .} # mangle as we currently do, via
nosfoo2a
proc foo2(a:int) {. extern2 .} # mangle as mylib_foo2 (**makes common case
simple**)
# for overloads:
proc foo2(a:int) {. extern2: "mysuffix" .} # mangle as mylib_foo2mysuffix
Run
(the word extern2 can be a better name, note that we could also define via
extern: "$0mysuffix" where $0 means mylib_foo2 but I want to make this syntax
as simple as possible, especially for common case of no overload)
## Note: when debugging (eg through gdb, lldb), using demangling should be ok
even without extern pragma