V
vippstar
/You/ do know that. The compiler doesn't. In your code you dereferenceEither you are not understanding me or I am not able to understand this
<p_strcmp> thing. This is your code:
compare these 2 paragraphs:
In theory, you get a <pointer to const void> and you use it to initialize
a <pointer to a const pointer to char> . In practice, you get a <pointer
to a pointer to char> and you are using it to initialize a <pointer to a
const pointer to char> and then dereference it to a <const pointer to
char>.
Because you already know that the input argument will be <char**> so we
a void * pointer and then use its value, which is not possible in ISO
C.
How do you get a char * if you dereference a void *?can simply dereference it and get a <char*> which could be used for
Here, you dereference a void pointer as I said before. This void *<strcmp> since <strcmp> does not require a <const pointer>. Hence It
could be simply this:
int p_strcmp(const void *pv1, const void *pv2)
{
return strcmp(*pv1, *pv2);
pointer is given the value of a char ** pointer. That's why RH assigns
it to such pointer, and then dereferences it. Consider this:
#include <stdio.h>
int f(void *p);
int main(void) {
int i = 10;
int *k = &i;
printf("%d\n", f(&k)); // pass address of int *, type is int **
return 0;
}
int f(void *p) {
int **i = p; // p points to an int **
return **i + 10;
}
It's the same thing.
P.S. Your signature appeared twice.