c++ - What is the difference between (void*) and (void(*)(argument type)) cast? -
this question has answer here:
void funcptr(int a);  int main(){    int k=1;    void (*funcptr2)(int);     funcptr2 = (void*)(funcptr);    // funcptr2 = (void(*)(int))(funcptr);     (*funcptr2)(k);    return 0; }  void funcptr(int a){    printf("%d", a); } what difference between (void*) , (void(*)(argument type) in function pointer type casting?
as result, not occur warning.
is wrong?  (void*) type casting
is wrong? (void*) type casting
yes, is.
c standard doesn't allow conversion of function pointer object pointer or assignment between them. if compiler warning level, may warnings/errors such compiling with:
gcc -wall -wextra -pedantic-errors -std=c11 file.c i not sure why thought casting function pointer. provided function pointer type matches function, assign it:
 funcptr2 = funcptr; aside:
you can use function pointer function:
 funcptr2(k); and use standard prototype main such as:
int main(void) 
Comments
Post a Comment