httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Laurie <>
Subject Re: cvs commit: apache/src mod_proxy.c (fwd)
Date Wed, 03 Jul 1996 15:47:51 GMT
Paul Richards wrote:
> Ben Laurie writes:
>  > > 
>  > > The code is wrong, p should not be a "const char *", it's only used to
>  > > pick up the error string from strerror and strerror returns a "char *".
>  > > 
>  > > The compiler warning is correct since the variable is not the same type
>  > > as the return parameter.
>  > 
>  > Nah. An assignment from char * to const char * is legal. Vice versa is not.
> I know it's legal, if it wasn't legal you'd have an error not a warning.

Hmm. I meant "legal and shouldn't generate a warning".

> The warning is correct, the variable's declaration does not match the
> type expected as specified by the function prototype, gcc 2.7.x creates
> lots more warnings than earlier versions, it's more pedantic.

This is altogether too narrow a definition of correct behaviour. For example,
an assignment of any pointer to or from a void * should not generate a warning,
nor should, say, assigning a char to an int. None of these types match yet a
compiler which warned about them would be broken.

It seems obvious to me that assignment from xxx * to const xxx * is harmless,
and even desirable in many cases, and hence should not generate a warning.

> In this case the warning is genuinely harmless but correct the warning
> properly not by casting to something it should have been in the first
> place (the cast makes the const a complete waste of time anyway, even
> if it had served some purpose in the first place, which it didn't).

It did serve a purpose, albeit a purely defensive one, namely that it would
be erroneous to write to the string returned by strerror. But, of course, const
is purely defensive anyway...

I think strerror is incorrectly defined... it should be
"const char *strerror(int);".

> It's very rare that sticking in a cast is the correct fix, it usually just
> masks the real situation.

Agreed. Which is why the above should not generate a warning.



Ben Laurie                  Phone: +44 (181) 994 6435
Freelance Consultant and    Fax:   +44 (181) 994 6472
Technical Director          Email:
A.L. Digital Ltd,           URL:
London, England.

View raw message