Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c++
Subject: Re: This code is effective for modest-sized numbers, but can you tell what it does?
Date: Tue, 10 May 2022 07:18:27 -0700
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <86mtfp4gjw.fsf@linuxsc.com>
References: <0c3601f0-fc8c-4bb9-a8b3-598ea1ca4a79n@googlegroups.com> <86fsm18i1c.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="14a2ae3f27dfeae71155063f7e16a495"; logging-data="32322"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19U6HFB1CGSchov6dUGDr3myEURlK1X+jw="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:hViJDYyweVVmnpfN43oZdVYPCPA= sha1:EAH7umMxIuI5fmRuMCBo6Ioahcs=
Xref: csiph.com comp.lang.c++:84022
Paavo Helde writes:
> 25.04.2022 15:27 Tim Rentsch kirjutas:
>
>> Juha Nieminen writes:
>>
>>> Graeme C. wrote:
>>
>> [...]
>>
>>>> for (int i=0; i>>
>>> std::vector::size() returns a value of type std::size_t. You
>>> shouldn't be using an int with it.
>>
>> I don't want to start a holy war, but in this particular case
>> there is no problem comparing a signed type to a size_t (which is
>> an unsigned type).
>
> I don't really care if such code uses signed or unsigned types.
> However, there is a problem when comparing signed and unsigned
> types, namely the gcc compiler issues warnings for them with -Wall,
> and sometimes these warnings are actually useful.
IME these warnings from gcc give false positives too often to
be used on every single compile. Of course it can be useful
to turn them on now and then, to make sure nothing is askew,
but trying to avoid them even in all the false positive cases
is IMO more trouble than it is worth.
> So, in order to not lose these useful warnings in the avalanche of
> non-useful ones, one should use matching types in such simple code,
> it does not cost anything.
That seems plainly false. Any change that incurs some programming
effort and disturbs what code is written obviously costs something.
A claim could be made that the cost is worth the benefit, but
clearly the cost is greater than zero.