Topic: char ** -> char const **
Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: Mon, 26 Sep 1994 14:16:03 GMT Raw View
jason@cygnus.com (Jason Merrill) writes:
>Would someone please explain to me again why this conversion is unsafe?
>I've seen the rationale a couple of times now, but I keep forgetting. I
>swear I'll save it this time...:)
I could have sworn I saved it last time, but I can't find it.
Oh well, the wetware backup seems to have worked, albeit with a rather
long access time ;-)
char *p, **pp;
const char *pc, **ppc;
pc = "foo"; // fine
pp = &p; // ok, `char **' on both sides
ppc = pp; // doubtful: `char **' -> `const char **'
*ppc = pc; // ok, `const char *' on both sides
*p = 'x'; // oops, `p' points to "foo" -
// we've attempted to modify a string literal!
--
Fergus Henderson - fjh@munta.cs.mu.oz.au
Author: h.b.furuseth@usit.uio.no (Hallvard B Furuseth)
Date: 22 Sep 1994 17:08:31 GMT Raw View
In article <JASON.94Sep21143003@deneb.cygnus.com> jason@cygnus.com (Jason Merrill) writes:
> Would someone please explain to me again why this conversion is unsafe?
char const *str = "foo";
char *x[1];
char const **y = (char const**)x;
*y = str;
**x = 'x'; // Modify *str
> Where's a FAQ list when you need one?
Still at rtfm.mit.edu, I suppose:-)
--
Regards,
Hallvard
Author: jason@cygnus.com (Jason Merrill)
Date: Thu, 22 Sep 1994 22:55:46 GMT Raw View
>>>>> Hallvard B Furuseth <h.b.furuseth@usit.uio.no> writes:
>> Where's a FAQ list when you need one?
> Still at rtfm.mit.edu, I suppose:-)
Not for this group.
Jason