L
lovecreatesbeauty
There is a warning/(error? I remember it is an error for line 10 on
some compilers before. At least on g++, it is an error.) for line 10. I
first read a similar example from `Expert C Programming -- Deep
Secrets, Perter van der Linden'. But I wonder why line 9 is ok but line
10 is illegal?
Is what Keith Thompson said in another post also helpful to understand
this question:
"... The implicit conversion rule applies only to void*, not to void**.
In this context, a void* is just another object type, and a void** is
just another pointer-to-object type. There's no implicit conversion
from one pointer-to-object type to another pointer-to-object type. ..."
void foo1(const char *p) {}
void foo2(const char **p) {}
int main(void)
{
char *p1;
char **p2;
foo1(p1); /* line 9: consistent type conversion */
foo2(p2); /* line 10: inconsistent type conversion */
}
The gcc tells:
$ gcc -W -Wall -std=c99 -pedantic test.c
....
test.c: In function `main':
test.c:10: warning: passing arg 1 of `foo2' from incompatible pointer
type
some compilers before. At least on g++, it is an error.) for line 10. I
first read a similar example from `Expert C Programming -- Deep
Secrets, Perter van der Linden'. But I wonder why line 9 is ok but line
10 is illegal?
Is what Keith Thompson said in another post also helpful to understand
this question:
"... The implicit conversion rule applies only to void*, not to void**.
In this context, a void* is just another object type, and a void** is
just another pointer-to-object type. There's no implicit conversion
from one pointer-to-object type to another pointer-to-object type. ..."
void foo1(const char *p) {}
void foo2(const char **p) {}
int main(void)
{
char *p1;
char **p2;
foo1(p1); /* line 9: consistent type conversion */
foo2(p2); /* line 10: inconsistent type conversion */
}
The gcc tells:
$ gcc -W -Wall -std=c99 -pedantic test.c
....
test.c: In function `main':
test.c:10: warning: passing arg 1 of `foo2' from incompatible pointer
type