Not sure if this is even possible. I need to pass a function from C to C++. It cannot be a function pointer.
C++ Function that I need to call:
template<class Lam>
void parfor(int N, Lam lam) {
lam(i);
}
C Function that I want to give to parfor (ptr can be a global pointer here):
void calc(int num) {
ptr[0] = num;
}
C Main to look like this:
include <ParFor.hpp>
parfor(calc, 1);
I could put my function definitions inside a header. On the C++ side I have a function (from an outside library) that takes a C++ lambda or a C++ functor. It's templated to a lambda
My current thinking is put my C functions inside a file, compile LLVM IR for them and somehow force inline the IR generated by clang into my C++ function. C calls mycppfunc(mycfunc). mycppfunc has the LLVM IR for mycfunc and is able to generate proper code. I tried this but but compiler crashes at link stage due to what seems to be incompatible IRs.