问题
The function defined in coreTelephony.h is
void _CTServerConnectionRegisterForNotification(CTServerConnectionRef,void *,void(*callback)(void));
Then I tried to call this function
int x = 0; //placehoder for callback
_CTServerConnectionRegisterForNotification(conn,kCTCellMonitorUpdateNotification,&x);
it return the error
incompatible pointer type passing int to parameter of type void(*)(void) in coretelephony obj c
What am I missing?
回答1:
The third argument of _CTServerConnectionRegisterForNotification
is a function pointer, and you pass a pointer to an int
. Even if you succeeded to do it using casts, later when the connection needs to notify you it will try to use the value you passed as a function, and since it is not a function, you most likely will see a crash.
Use a function not an int:
void callback()
{
}
and then in your current code:
_CTServerConnectionRegisterForNotification(conn,kCTCellMonitorUpdateNotification,&callback);
回答2:
Here, the third argument to _CTServerConnectionRegisterForNotification()
is meant to be a pointer to a function having
void
return type- Accepting no parameter.
You cannot pass the address of an int
in that case. It is wrong and will cause undefined behavior.
来源:https://stackoverflow.com/questions/30275026/incompactable-pointer-type-passing-int-to-parameter-of-type-voidvoid-in-cor