sfabel
sfabel

Reputation: 31

C (gcc) warning: initialization from incompatible pointer type when calling pthread_cleanup_push()

gcc version 4.3.3 under Ubuntu Linux 9.04 in case that is relevant.

This is the offending code:

pthread_cleanup_push(ctl_cleanup, NULL);

with ctl_cleanup() defined as

void* ctl_cleanup(void *arg);

There are other instances where this warning pops up, in similar circumstances. The warning also appears if I call something like

pthread_cleanup_push(pthread_mutex_unlock, (void *)&m);

where m is of type pthread_mutex_t. The warning reads:

warning: initialization from incompatible pointer type

I don't understand. I've passed other things around using void pointers (e.g. when passing arguments to a pthread) without that warning. Can someone help me out?

Upvotes: 1

Views: 4111

Answers (1)

Seth Robertson
Seth Robertson

Reputation: 31461

void ctl_cleanup(void *arg);

The above is the prototype you are looking for. It returns void, not a pointer to void.

The extra * in the function is because it takes a pointer to a function taking one void* argument returning void.

Upvotes: 4

Related Questions