Boost logo

Boost :

Subject: Re: [boost] Towards a Warning free code policy proposal
From: Emil Dotchevski (emil_at_[hidden])
Date: 2010-08-29 02:23:06


On Sat, Aug 28, 2010 at 2:11 PM, Mika Heiskanen <mika.heiskanen_at_[hidden]> wrote:
> On Sat, 2010-08-28 at 22:17 +0300, Robert Ramey wrote:
>> d) some were too hard to fix/eliminate comparison between signed/unsigned -
>> I just left them because I didn't know how to fix them
>
> Am I missing some complication I'm not aware of?
>
> In my experience this warning is just about always the result of
> using int for variables which should be of type size_t, as in
>
>  for(int i=0; i<object.size(); i++)
>
> If I cannot redefine all the types to unsigned, something like this
> usually fixes the problem:
>
>  if ( size >= 0 && static_cast<size_t>(size) < object.size() )
>
> Writing static_casts is annoying, but it is often necessary
> if you want to remain -Wall -pedantic.

This is a good illustration of one of the problems with "fixing"
warnings: this is often done with casts, and casts are way more
dangerous than the built-in implicit conversions for which the
compiler is warning about.

Emil Dotchevski
Reverge Studios, Inc.
http://www.revergestudios.com/reblog/index.php?n=ReCode


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk