Incompatible pointer type passing int to parameter of type void (*) (void) in coretelephony obj c
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 returns an error
incompatible pointer type passing int to parameter of type void (*) (void) in coretelephony obj c
What am I missing?
source to share
Here, the third argument _CTServerConnectionRegisterForNotification()
is for a pointer to a function having
-
void
return type - Do not accept any parameters.
In this case, you cannot transfer the address int
. This is wrong and will cause undefined behavior .
source to share
The third argument _CTServerConnectionRegisterForNotification
is a function pointer and you are passing a pointer to int
. Even if you manage to do it with broadcasts, later on when the connection is supposed to notify you it will try to use the value you passed as a function and since it is not a function you will most likely see a failure.
Use the not int function:
void callback()
{
}
and then in your current code:
_CTServerConnectionRegisterForNotification(conn,kCTCellMonitorUpdateNotification,&callback);
source to share