From mboxrd@z Thu Jan 1 00:00:00 1970 From: Martin Kahlert To: gcc-bugs@gcc.gnu.org Subject: Is this a bug? Date: Wed, 06 Dec 2000 03:42:00 -0000 Message-id: <20001206124239.A20108@keksy.muc.infineon.com> X-SW-Source: 2000-12/msg00130.html List-Id: Hi! I have code similar to this: #include #include #include void f(const char **x) { while(*x) { puts(*x); x++; } } int main(int argc,char *argv[]) { char **buffer; buffer = calloc(3, sizeof(char*)); buffer[0] = strdup("Hello"); buffer[1] = strdup("World"); f(buffer); return 0; } gcc -Wall -o prog prog.c gives: t.c: In function `main': t.c:23: warning: passing arg 1 of `f' from incompatible pointer type (the warning comes from the missing const) Is this a bug? At least it is an inconsistency: f(const char *buffer) { puts(buffer); } int main() { char b[] = "Hello World"; f(b); return 0; } works without any warning! Thanks for any clarification, Martin. -- The early bird gets the worm. If you want something else for breakfast, get up later. >>From jsm28@cam.ac.uk Wed Dec 06 03:55:00 2000 From: "Joseph S. Myers" To: Martin Kahlert Cc: Subject: Re: Is this a bug? Date: Wed, 06 Dec 2000 03:55:00 -0000 Message-id: References: <20001206124239.A20108@keksy.muc.infineon.com> X-SW-Source: 2000-12/msg00131.html Content-length: 531 On Wed, 6 Dec 2000, Martin Kahlert wrote: > t.c: In function `main': > t.c:23: warning: passing arg 1 of `f' from incompatible pointer type > (the warning comes from the missing const) > Is this a bug? No; you can pass a "char **" to a function expecting a "char **" or a "char *const *", but not to one expecting a "const char **" or a "const char *const *". It's only at the first level of indirection that you can have different type qualifiers in the expected type and the type passed. -- Joseph S. Myers jsm28@cam.ac.uk