TITLE: conversions of pointer-to-pointers (Newsgroup: comp.lang.c++.moderated, 23 Jan 99) CLAMAGE: Steve Clamage >>> char * bad; >>> >>> const char ** ptr = & bad; >>> >>> >>> The above assignment is illegal in both C and C++. GLASSBOROW: Francis Glassborow > Why? > > the type of &bad is char**. I do not know of a rule that prohibits > converting that to char const **. Could you elucidate CLAMAGE: Steve Clamage clamage@Eng.Sun.COM> The question is in every FAQ for C and C++ that I am familiar with. Here's the answer from the comp.std.c++ FAQ: -------------------------------------------------------------------- 1. Why does the draft standard say that T** to const T** is not a standard conversion? The rules for qualification conversions (standard conversions that add const or volatile specifiers) are given in section 4.4 of the draft standard. T** to const T** is not a qualification conversion; this is not an oversight, but is necessary to preserve const safety. Consider the following. (This example was provided by James Kanze, but the general idea behind it is well known.) const char c = 'a'; char* p; char** pp = &p; const char** ppc = pp; // If this were not illegal. *ppc = &c; // Oops: where does p point? *p = 'b'; // And what is wrong here? The rules in section 4.4 of the draft standard prohibit this sort of error. __________________________________________________________ See the C++ Tip-of-the-day home page for more information. http://www.ses.com/~clarke/TableOfContents.html