public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Kaveh R. Ghazi" <ghazi@caip.rutgers.edu>
To: gcc-bugs@gcc.gnu.org, gcc@gcc.gnu.org
Subject: Strange sign-compare results
Date: Sun, 16 Dec 2001 13:46:00 -0000	[thread overview]
Message-ID: <200112162112.QAA24486@caip.rutgers.edu> (raw)

Given this code:

 > int foo(unsigned int u, unsigned int u1, unsigned int u2,
 > 	unsigned short us1, unsigned short us2,
 > 	int i1, int i2, short s1, short s2)
 > {
 >   if (u < (s1-s2))
 >     return 0;
 > 
 >   if (u < (us1-us2))
 >     return 0;
 > 
 >   if (u < (i1-i2))
 >     return 0;
 >   
 >   if (u < (u1-u2))
 >     return 0;
 > 
 >   return 1;
 > }

compiling it (on sparc-solaris2) with -Wsign-compare (using 2.95.2,
3.0.3 (pre) or 3.1) yields:

 > foo.c:5: warning: comparison between signed and unsigned
 > foo.c:8: warning: comparison between signed and unsigned
 > foo.c:11: warning: comparison between signed and unsigned

I.e. the last compare of "u < (u1-u2)" doesn't warn.  Is this a bug or
feature?  Doesn't (u1-u2) become an integer?  Please explain. :-)

		Thanks,
		--Kaveh
--
Kaveh R. Ghazi			Engagement Manager / Project Services
ghazi@caip.rutgers.edu		Qwest Internet Solutions

             reply	other threads:[~2001-12-16 21:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-12-16 13:46 Kaveh R. Ghazi [this message]
2001-12-16 13:57 ` Neil Booth
2001-12-16 15:17   ` Neil Booth
2001-12-16 17:59 Kaveh R. Ghazi
2001-12-17  0:02 ` Neil Booth

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=200112162112.QAA24486@caip.rutgers.edu \
    --to=ghazi@caip.rutgers.edu \
    --cc=gcc-bugs@gcc.gnu.org \
    --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).