httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Laurie <...@algroup.co.uk>
Subject Re: [PATCH] Resolve BUILD warnings under ULTRIX/mips (take 3)
Date Sat, 11 Apr 1998 15:55:45 GMT
Dean Gaudet wrote:
> 
> Nah casts aren't ever safe ;)
> 
> Need I drag out the crypto example again?  Such an innocent cast... such a
> devastating effect.  The code looked something like this:
> 
>     tmp = (unsigned)gen_salt;
> 
> when it was supposed to be:
> 
>     tmp = (unsigned)gen_salt();
> 
> A world of difference between the two of course.  But the cast hides it.
> I forget what code it was in, but that's a real life mistake.
> 
> And C++ doesn't help it.

That's where you are wrong:

	tmp=static_cast<unsigned>(gen_salt);

catches this mistake:

Test7.cpp(155) : error C2440: 'static_cast' : cannot convert from 'int
(__cdecl *)(void)' to 'unsigned int'
This conversion requires a reinterpret_cast, a C-style cast or
function-style cast

It does irritate me that people are so prejudiced against something they
don't even know how to use.

(BTW, I tested this on VC++ and g++. g++ didn't work (version 2.7.x)).

Cheers,

Ben.

-- 
Ben Laurie            |Phone: +44 (181) 735 0686|  Apache Group member
Freelance Consultant  |Fax:   +44 (181) 735 0689|http://www.apache.org
and Technical Director|Email: ben@algroup.co.uk |
A.L. Digital Ltd,     |Apache-SSL author    http://www.apache-ssl.org/
London, England.      |"Apache: TDG" http://www.ora.com/catalog/apache

Mime
View raw message