Is there a way to declare a C variadic function and call it from Fortran? I need to call this function to compute some dot products between vectors labeled with a string. My idea was to declare something like the following, where the variable list of arguments contains string literals. If the variable list of arguments is empty, then I would do a lookup among the standard labels and perform the calculation. If the user specified two labels I would retrieve those two vectors and get their dot product:
extern "C" void compute_dot_product(double * dot_product, ...)
{
va_list args;
va_start(args, NULL);
char * label1 = va_arg(args, char *);
if (!label1)
{
// Do standard label lookup and compute dot product
}
else
{
// Compute dot product between the vectors with the specified labels
char * label2 = va_arg(args, char *);
}
va_end(args);
}
the only problem is that I can compile my C library and link it to a Fortran executable, but I get a runtime error when I try to access the variable list of arguments. Any idea if what I am trying to do is possible? A possible solution would then be to split into two functions: one that does the standard label lookup (0 argument case), the other that handles the non-standard label lookup (2 argument case). I would rather avoid this solution though.