public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Russ Allbery <rra@stanford.edu>
To: gcc@gcc.gnu.org
Subject: Re: comparisons..
Date: Thu, 13 Jul 2000 17:30:00 -0000	[thread overview]
Message-ID: <ylwvip8sex.fsf@windlord.stanford.edu> (raw)
In-Reply-To: <396E5ABD.856EACF4@uow.edu.au>

Andrew Morton <andrewm@uow.edu.au> writes:

> There are probably some bugs hiding behind "comparison between signed
> and unsigned", but I didn't check these - there were many hundreds.

This is a rather interesting warning.  I've recently gone through the
exercise of making some code free of this warning, and I'm convinced that
it results in higher code quality, but it does require some work.  Most
code that I see plays fairly rough and loose with whether things are
signed or unsigned and gets away with it because the values that it deals
with are never high enough to cause a problem.  To be really correct, code
should care and deal with those boundary cases correctly.

Unfortunately, fixing these warnings often requires a good bit of fiddling
and can have some propagation effects similar to trying to const-ify old
code that makes fixing them all sometimes impractical for old code bases.

I don't think a lot of C programmers pay enough attention to signed vs.
unsigned issues, including a lot of interface designers.  Note, for
example, the interface to write:

  ssize_t write(int fildes, const void *buf, size_t nbyte);

What *do* you return if you can successfully write out as one block more
data than will fit in the range of ssize_t, but that will fit into size_t
(which is normally twice as large on the positive end)?  :)

-- 
Russ Allbery (rra@stanford.edu)             < http://www.eyrie.org/~eagle/ >

  reply	other threads:[~2000-07-13 17:30 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-07-12 22:58 comparisons Andrew Morton
2000-07-12 23:35 ` comparisons Michael Meissner
2000-07-12 23:48   ` comparisons Andrew Morton
2000-07-12 23:57     ` comparisons Michael Meissner
2000-07-13  0:24       ` comparisons Andrew Morton
2000-07-13  1:05         ` comparisons Nick Burrett
2000-07-13  1:47           ` comparisons Andrew Morton
2000-07-13  9:12             ` comparisons Joe Buck
2000-07-13 14:48               ` comparisons Andi Kleen
2000-07-13 21:46               ` comparisons Andrew Morton
2000-07-13  0:24     ` comparisons Martin v. Loewis
2000-07-13  1:09       ` comparisons Andrew Morton
2000-07-13  1:36         ` comparisons Nick Burrett
2000-07-13  1:47           ` comparisons Andrew Morton
2000-07-13  6:39         ` comparisons Andrew Morton
2000-07-13  9:11           ` comparisons Joe Buck
2000-07-13  9:45             ` comparisons Bruce Korb
2000-07-13 10:32               ` comparisons Joe Buck
2000-07-13 15:14             ` comparisons Russ Allbery
2000-07-13 17:11               ` comparisons Philipp Thomas
2000-07-28  5:48           ` comparisons Nix
2000-07-13  9:44         ` comparisons Gerald Pfeifer
2000-07-13 17:12           ` comparisons Andrew Morton
2000-07-13 17:30             ` Russ Allbery [this message]
2000-07-13 17:48               ` comparisons Michael Meissner
2000-07-14  4:22             ` comparisons Toon Moene
2000-07-14 10:57               ` comparisons Richard Henderson
2000-07-14 12:43                 ` comparisons Toon Moene
2000-07-14 12:52                   ` comparisons Richard Henderson
2000-07-14 13:53                     ` comparisons Toon Moene
2000-07-14 14:00               ` comparisons Martin v. Loewis
2000-07-15 17:35               ` comparisons Joe Buck
2000-07-12 23:54 ` comparisons Martin v. Loewis
2000-07-13 10:09 comparisons Phil Edwards
2000-07-13 11:18 ` comparisons Michael Meissner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ylwvip8sex.fsf@windlord.stanford.edu \
    --to=rra@stanford.edu \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).