If C functions you want to import are declared with specific calling convention, you would need to import them with same calling convention. https://osdev.wiki/pages/calling_conventions.html
If you import C functions using header pragma, you would not need to specify calling convention.
C macro is not a C functions, just looks like a function when you call it. You don't need to specify calling convention.
For example:
{.emit: """
#define CMACRO(a,b) ((a) > (b) ? (a): (b))
""".}
proc cmacro(a, b: int): int {.importc: "CMACRO", nodecl.}
proc cmacro(a, b: float): float {.importc: "CMACRO", nodecl.}
echo cmacro(10, 100)
echo cmacro(-1.0, 0)
If C macros are defined in header file, you need to use header pragma instead of nodecl.
Thanks.
Another question: I've read that calling conversions can change a proc's behavior. For example a {.cdecl.} is a function pointer, and a {.closure.} is an object. Is there any other special rule about them?
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.