I use this resource to help me with function pointers: here But in this code (see below), gcc compilation says:
line 15: warning: dereferencing 'void*' pointer
line15:error:called object *foo is not a function
The code is here:
#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
void print_mess(void *ptr)
{
char *message = ptr;
printf("%s\n",message);
}
void main()
{
void* foo = print_mess;
char *mess = "Hello World";
(*foo)((void*)mess);
}
A very simple test function to refresh my knowledge, and I'm confused to even run into such a problem, not to mention its placement on SO.
source
share