Por ejemplo:En C, ¿cuál es la diferencia entre `& function` y` function` cuando se pasa como argumentos?
#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);
}
La ejecución de este me sale el siguiente:
> 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.
Mis dos preguntas son:
- ¿Cuál es la diferencia entre un prototipo de función definida con
(* proto)
y uno definido sin? - ¿Cuál es la diferencia entre llamar a una función con el operador de referencia (
&
) y sin?
No creo que haya una diferencia. No publicando como respuesta porque no estoy realmente seguro. – JAB
posible duplicado de [Punteros de función en el operador de dirección C "innecesario"] (http://stackoverflow.com/questions/258422/function-pointers-in-c-address-operator-unnecessary) – outis