httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Richards <p.richa...@elsevier.co.uk>
Subject Re: cvs commit: apache/src mod_proxy.c (fwd)
Date Wed, 03 Jul 1996 16:06:20 GMT
Jim Jagielski writes:
 > Hmmm... I seem to recall that const could be initialized (once, of
 > course) but never reassigned later. Thus,
 > 
 > 	const char *p = "Howdy";
 > 
 > is OK, but
 > 
 > 	const char *p;
 > 	p = "Howdy";
 > 
 > most probably ain't.

This isn't right. "const char *p" means that p is a pointer to a
constant string. The value of "p" can be freely changed but the thing
it points to cannot be;

p = "Howdy";
p = "Hi";

would be perfectly valid but

*p = '\0';

would be illegal.

The compiler "warning" was perfectly valid, it was warning you that a
pointer to an area of memory that could be changed was being assigned
to a pointer that would not let you change it. It may or may not be
what you expected, hence a warning.

If the example was different e.g.

p = malloc(20);

then the warning would certainly be appropriate.



Mime
View raw message