I need to create a macro
DISP(sqrt, 3.0)
that expands into
printf("sqrt(%g) = %g\n", 3.0, sqrt(3.0));
Here is my current attempt that doesn't quite work yet:
#include <math.h>
#include <stdio.h>
#define DISP(f,x) printf(#f(%g) = %g\n", x, f(x))
int main(void)
{
DISP(sqrt, 3.0);
return 0;
}
gcc -E
shows that I currently have an extra double quote in there.
If I put any double quotes or escaped double quotes before my #f or if I use ##f the macro no longer expands. How to fix?
"
don't match. There is only one in the code - see answer. – Weather Vane