1. I have this piece of test code:
Code:
#include <stdio.h>
void callee(void *msg)
{
char *m = (char *)msg;
printf("%s\n", m);
}
void caller(void *(callee)(void *), void *arg)
{
printf("caller\n");
callee(arg);
}
int main()
{
caller(callee, "caller calling callee");
return 0;
}
% gcc -Wall testcall.c -o testcall
testcall.c: In function `main':
testcall.c:15: warning: passing arg 1 of `caller' from incompatible pointer type
What did I do wrong? caller's definition says callee should be a function that takes a void * parameter and returns void. Isn't callee exactly that?
2. Solaris' man page for pthread_cleanup_push() apperas to have a typo, as suggested by Salem. I wrote some code to test that "void (*handler, void *)," format and I got a syntax error. I will try to post this to a Solaris user forum to get this documentation bug confirmed. On the other hand, I checked the pthread.h file that contains the prototype of pthread_cleanup_push() :
Code:
void __pthread_cleanup_push(void (*)(void *), void *, caddr_t, _cleanup_t *);
typedef void (*_Voidfp)(void*); /* pointer to extern "C" function */
#define pthread_cleanup_push(routine, args) { \
_cleanup_t _cleanup_info; \
__pthread_cleanup_push((_Voidfp)(routine), (void *)(args), \
(caddr_t)_getfp(), &_cleanup_info);
#define pthread_cleanup_pop(ex) \
__pthread_cleanup_pop(ex, &_cleanup_info); \
}
Note that the type of the first parameter of __pthread_cleanup_push() is
How is it different from
? Interestingly, if I add a prototype for caller():
Code:
void caller(void (*)(void *), void *);
A bunch of syntax errors are resulted:
% gcc -Wall testcall.c -o testcall
testcall.c:11: error: conflicting types for 'caller'
testcall.c:3: error: previous declaration of 'caller' was here
testcall.c:11: error: conflicting types for 'caller'
testcall.c:3: error: previous declaration of 'caller' was here
But if I add it like this:
Code:
void caller(void *(void *), void *);
it is fine. What is going on? I thought the first * means the parameter is a function, rather than the funtion returning a void *. Am I wrong?