Meaning of "Calling convention" in C/Assembler and in Nim is bit different.

In C/Assembler, calling convention is about how parameters are passed to a 
function, result is returned and other low level rules for functions. 
<https://en.wikipedia.org/wiki/Calling_convention>

In some platforms, many calling conventions are used. When you call a function, 
you have to use the corresponding calling convention. Calling a function in 
different calling convention result in undefined behavier.

In Nim, calling convention is about C/Assembler calling convention, how Nim 
generate C code from Nim procedure, how Nim import C functions and higher level 
things. This section in Nim manual lists Nim calling conventions: 
<https://nim-lang.org/docs/manual.html#types-procedural-type>

stdcall, cdecl, safecall, fastcall, thiscall, syscall are C/C++/Assembler 
calling conventions and they are explained here: 
<https://en.wikipedia.org/wiki/X86_calling_conventions>

nimcall and noconv is about which C/Assembler calling convention Nim choose 
when generating C function code from Nim procedure. Explained here: 
<https://nim-lang.org/docs/manual.html#types-procedural-type>

`closure` is an object containing the proc pointer and the pointer to 
implicitly passed environment.

Only closure calling convention have different behavior as it can access local 
variables when it is nested. Other calling conventions can be nested but cannot 
access local variables in outer procedure. `inline` might affect performance, 
but output of a program doesn't change by adding or removing inline to procs. 
Other calling convention might also slightly affect performance but doesn't 
change behavior. But choosing right calling convention can be important when 
you import C functions or export Nim functions to C. In that case, using wrong 
calling convention results in undefined behavior. 

Reply via email to