How can I compile a code with target C containing function definition inside?
I saw post using With
. But this just inserts the function in the appropriate place like macros in C.
Suggestion with With
f = Compile[{{x, _Real}},
g[y] = y^2;
g[x]
, CompilationTarget -> "C"
]
Calls Main
:
In[12]:= CompilePrint[f]
1 argument
3 Real registers
Underflow checking off
Overflow checking off
Integer overflow checking on
RuntimeAttributes -> {}
R0 = A1
Result = R2
1 V17 = MainEvaluate[ 2
Function[{x}, g[y] = y ][ R0]]
2 R2 = MainEvaluate[ Hold[g][ R0]]
3 Return
g
as a separate function instead of making the definition withinCompile[]
? $\endgroup$MainEvaluate
? $\endgroup$