Topic: Understanding char** to const char**
Author: NULL@NULL.NULL ("Tom s")
Date: Mon, 8 May 2006 17:34:09 GMT Raw View
I'm sure a lot of you have seen the following code which demonstrates why=
=20
we can't implicitly convert from:-
char**
to:
const char**
Here's the code (written originally by James Kanze):
const char c =3D 'a';
char* p;
char** pp =3D &p;
const char** ppc =3D pp; // Supposing that this were not illegal.
*ppc =3D &c; // Oops: where does p point?
*p =3D 'b'; // And what is wrong here?
I've read the above code many times but never understood it. Even when I=20
thought about it thoroughly and slowly, I couldn't comprehend what was=20
going on.
Anyway, I came across the code again today, and finally I resolved to=20
grasp an understanding of it once and for all. So I drew a diagram, which=
,=20
after a few minutes of analysing, made me understand. With the hope of=20
helping others, here's the diagram:
http://img315.imageshack.us/img315/2876/undconst6kk.jpg
I've posted this to more than one newsgroup, so if you would like to=20
reply, I'd appreciate if you would keep the discussion in comp.lang.c++.
-Tom=E1s
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]