Hi all, I saw this code in SO to declare a function pointer.
(int -> int)
But how do i declare a function pointer of a function with no return type and more than one parameter ? Thanks in advance.Hi,
proc are already pointer in Nim so it's as easy as a cast :
var fPtr : pointer = getFunctionPointer() # How you get your function pointer may vary
var myproc : (proc(arg: int) {.cdecl, gcsafe.}) = cast[(proc(arg: int) {.cdecl, gcsafe.})](fPtr)
myproc(3)
There is more example here : https://nim-lang.org/docs/dynlib.html#examples-loading-a-simple-c-function.
Note that stdcall pragma is windows specific and should be replaced by cdecl on Linux.
arrow syntax is just a sugar. https://nim-lang.org/docs/sugar.html#-%3E.m%2Cuntyped%2Cuntyped
type P = proc(a: int): int
@SolitudeSF Yes, that's what i wanted.
type
fnPtr = (int, int)
I want something like this. A function with 2 int params and no return value.var fnPtr1: proc(a: int, b: int)
#or
import sugar
var fnPtr2: (int,int) -> void