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: Mon, 25 Apr 2022 05:27:27 -0700
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <86fsm18i1c.fsf@linuxsc.com>
References: <0c3601f0-fc8c-4bb9-a8b3-598ea1ca4a79n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="2b2bd3060d7fb14ae545fc6b32585799"; logging-data="20280"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+p83aKqqiGcbNVoco5yNcfEt5SVbugwJQ="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:Rl/QVe1HO5zDPHiPbNBKkj/La0w= sha1:O46zvg311Fk4PXsvbZQNopOV5/4=
Xref: csiph.com comp.lang.c++:83720
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). More generally, whenever a value of a signed
type has a non-negative value, as is obviously true in this
construct, then there is never a problem comparing a value of a
signed type to a value of an unsigned type.
Some people prefer using an unsigned type for indexing variables
like 'i' above, and that a reasonable style choice here IMO. But
there is nothing logically wrong with giving 'i' a signed type
here instead.