I have a C++ framework where some calculations are delegated to (sometimes auto generated) C functions or C++ functions with external "C" linkage. These are low-level routines that must be evaluated very fast and with minimal overhead and they typically reside in separate shared objects/DLLs. Their current signature is something along the lines of:
int my_generated_function(const double* input, double* output, double* work);
which will reside in a shared library loaded using dlopen
on POSIX or LoadLibrary
on Windows. The corresponding function pointers are extracted using dlsym(handle, "my_generated_function")
on POSIX or GetProcAddress(handle, TEXT("my_generated_function"))
on Windows.
Is it safe and portable to augment the signature with a FILE object pointer?
int my_generated_function(const double* input, double* output, double* work,
FILE* logfile);
Note that the shared object containing my_generated_function
might have been compiled with a different (but binary compatible) compiler than the code that loads the shared object.
extern "C"
. – Homerusgcc
andclang
(which are binary compatible) for example? – HomerusFILE *
is an opaque pointer to some object or something within the runtime, this means that the DLL and the user of the DLL need to be using the same runtime. Different runtime versions could conceivably have differentFILE
object layouts. And the runtime in use by whatever component does the file open will need to share its tables and data with whatever other components, DLLs, that are being used. I am not sure if a DLL would load its own specific runtime that would be different from that of the using process or not. – Fauch