I am reviewing some optimisation libraries and came across the function signature
double solvopt(unsigned short n,
double x[],
double fun(),
void grad(),
double options[],
double func(),
void gradc()
)
note that fun() and gard() are passed as function. My question is if this is valid standard C grammar.
Thanks.
The use of
double fun()rather thandouble (*fun)()is an archaic form,that was only valid in standard C and never in C++,and if I remember correctly, only when declaring a function argument. (much likeary[]which is legal for a function argument, but not for an uninitialized variable)Since it isn’t possible (in C) to pass a function by value to another function, the compiler just took
double fun()to mean a pointer to a function that returned a double.So this is valid (but
archaic.has fallen out of favor)