Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!news.cs.indiana.edu!att!att!dptg!ulysses!andante!alice!ark From: ark@alice.att.com (Andrew Koenig) Newsgroups: comp.lang.c Subject: Re: Is this a valid ANSI program? Message-ID: <20461@alice.att.com> Date: 26 Jun 91 18:41:19 GMT References: <609@mtndew.Tustin.CA.US> Reply-To: ark@alice.UUCP () Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 37 In article <609@mtndew.Tustin.CA.US> friedl@mtndew.Tustin.CA.US (Stephen J. Friedl) writes: > void foo(const char **xxx) { } > main() > { > char **p = 0; > foo(p); > } > The compiler claims that the argument /p/ to the function foo() > is incompatible with the prototype, and I just don't believe it. The compiler is correct: you cannot convert char ** to const char ** . To see why, consider the following program fragment: main() { const char victim = '?'; char *accomplice; const char **sneak = &accomplice; /* */ *sneak = &victim; *accomplice = '!'; } If char ** could be converted to const char **, the line with the comment would be legal. None of the other lines is the least bit controversial; the declarations are surely beyond reproach, the assignment to *sneak places the address of a "const char" into a "const char *", and the assignment to *accomplice assigns an "int" to a "char". Thus allowing the commented line would open a hole in the type system by allowing you to modify a "const char" object without an explicit cast. -- --Andrew Koenig ark@europa.att.com