This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Relaxing -Wsign-compare
On 20-Sep-2001, Richard Henderson <rth@redhat.com> wrote:
>
> Make 'i' a size_t like it ought to have been in the first place.
Using unsigned types for loop indices is error-prone,
because it's easy to make mistakes like this one:
size_t i;
...
for (i = n - 1; i >= 0; i--) {
...
}
Good compilers such as gcc will warn about such mistakes,
but nevertheless I think the danger of accidental wrap-around
causing problems like this is still a good argument for
preferring signed types for loop indices, except for cases where
there is a specific reason why the type needs to be unsigned.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.