httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Laurie <...@gonzo.ben.algroup.co.uk>
Subject Re: cvs commit: apache/src mod_proxy.c (fwd)
Date Wed, 03 Jul 1996 18:16:01 GMT
Paul Richards wrote:
> 
> 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.

But, but ... to a C compiler:

p="xyzzy";

and

p=malloc(6);

are essentially identical (as far as constness and areas of memory are
concerned).

"xyyzy"[0]='a';

is legal, if bizarre, C. That may seem like a tangent, but it isn't (honest).

Cheers,

Ben.

> 
> If the example was different e.g.
> 
> p = malloc(20);
> 
> then the warning would certainly be appropriate.
> 
> 

-- 
Ben Laurie                  Phone: +44 (181) 994 6435
Freelance Consultant and    Fax:   +44 (181) 994 6472
Technical Director          Email: ben@algroup.co.uk
A.L. Digital Ltd,           URL: http://www.algroup.co.uk
London, England.

Mime
View raw message