6
是否可以在Nimrod中使用函數指針?如何在Nimrod中使用函數指針?
我已經試過是:
type fptr = (proc(int):int)
proc f(x:int): int =
result = x+1
var myf : fptr = f
echo myf(0)
但是當我嘗試編譯,我得到:
Hint: added path: 'C:\Users\Peter\.babel\pkgs\' [Path]
Hint: used config file 'C:\Program Files (x86)\Nimrod\config\nimrod.cfg' [Conf]
Hint: system [Processing]
Hint: hello3 [Processing]
Error: internal error: GetUniqueType
Traceback (most recent call last)
nimrod.nim nimrod
nimrod.nim handleCmdLine
main.nim mainCommand
main.nim commandCompileToC
modules.nim compileProject
modules.nim compileModule
passes.nim processModule
passes.nim processTopLevelStmt
cgen.nim myProcess
ccgstmts.nim genStmts
ccgexprs.nim expr
ccgstmts.nim genStmts
ccgexprs.nim expr
ccgstmts.nim genVarStmt
ccgstmts.nim genSingleVar
cgen.nim assignGlobalVar
ccgtypes.nim getTypeDesc
ccgtypes.nim getTypeDescAux
ccgtypes.nim genProcParams
cgen.nim fillLoc
ccgutils.nim getUniqueType
msgs.nim internalError
msgs.nim rawMessage
msgs.nim rawMessage
msgs.nim handleError
您也可以使用新的proc類型語法。只需導入'future'模塊並用'(int - > int)'替換'(proc(x:int):int)'。 – dom96