I know this is a duplicate. I've searched already but none address the problem I'm having. NOTE in an attempt to single out my confusion I have tried to simplify the typecast from the original. Hopefully it isn't undefined behaviour
Declaring a pointer to a function
Int (*funcPtr)(void*,void*);
Strcmp declaration
int strcmp (char *, char *);
Typecasting a function pointer
FuncPtr = (int (*)(void*, void*))strcmp
This is where I get confused. I understand Typecasting a function pointer we have created. So type casting FuncPtr for example just changes what type of function funcPtr can point to. I have also read that the name of a function Is a function pointer to itself so Typecasting strcmp and using my understanding from above,
int (*)(void*, void*))strcmp
Strcmp can now point to a function that takes two pointers to void and returns an int which Is clearly wrong as like arrays I think the function name can't be a pointer to another function.
Because of my understanding above I fail to see how you can assign the address of strcmp to FuncPtr with the following typecast
FuncPtr = (int (*)(void*, void*))strcmp
As changing what the function pointer strcmp points to doesn't change the arguments and return type of strcmp.
I would really appreciate some knowledge I'm just so confused.
FuncPtr, what type? Please note that the C language is case-sensitive.int (*)(void*, void*))and then cast the address ofstrcmpto that type?" then I can answer it. All the other things in your question makes it unclear, however. Also for the record, strcmp has the following format, which matters here:int strcmp(const char *s1, const char *s2);.