For example:
#include <stdio.h> typedef void (* proto_1)(); typedef void proto_2(); void my_function(int j){ printf("hello from function. I got %d.\n",j); } void call_arg_1(proto_1 arg){ arg(5); } void call_arg_2(proto_2 arg){ arg(5); } void main(){ call_arg_1(&my_function); call_arg_1(my_function); call_arg_2(&my_function); call_arg_2(my_function); }
Running this I get the following:
> tcc -run try.c hello from function. I got 5. hello from function. I got 5. hello from function. I got 5. hello from function. I got 5.
My two questions are:
(* proto)
and one defined without?&
) and without?There is no difference. For evidence see the C99 specification (section 6.7.5.3.8).
"A declaration of a parameter as ‘‘function returning type’’ shall be adjusted to ‘‘pointer to function returning type’’, as in 6.3.2.1."
There is no difference between &function and function - they're both addresses. You can see this by printing them both:
function bar(); .... printf("addr bar is 0x%d\n", &bar); printf("bar is 0x%d\n", bar);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With