I just noticed that this compiles without any errors or warnings using -pedantic -Wall
with both gcc
and clang
.
#include <stdio.h>
int x = 0;
void func(int f(const char *)) {
f("func()!");
}
int main(void) {
func(puts);
}
It appears that the parameter f
is treated like pointer to function int (*)(const char *)
in this case.
But this a behavior that I have never seen or heard anything about. Is this legal C code? And if so then what happens when you have a function as a parameter to a function?