* Strange sign-compare results
@ 2001-12-16 13:46 Kaveh R. Ghazi
2001-12-16 13:57 ` Neil Booth
0 siblings, 1 reply; 5+ messages in thread
From: Kaveh R. Ghazi @ 2001-12-16 13:46 UTC (permalink / raw)
To: gcc-bugs, gcc
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Strange sign-compare results
2001-12-16 13:46 Strange sign-compare results Kaveh R. Ghazi
@ 2001-12-16 13:57 ` Neil Booth
2001-12-16 15:17 ` Neil Booth
0 siblings, 1 reply; 5+ messages in thread
From: Neil Booth @ 2001-12-16 13:57 UTC (permalink / raw)
To: Kaveh R. Ghazi; +Cc: gcc-bugs, gcc
Kaveh R. Ghazi wrote:-
> 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. :-)
No, the type of the result is the type of the operands for most (all?)
operators in C.
The others convert the unsigned operand to signed, and therefore the
result of the subtraction is signed.
Neil.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Strange sign-compare results
2001-12-16 13:57 ` Neil Booth
@ 2001-12-16 15:17 ` Neil Booth
0 siblings, 0 replies; 5+ messages in thread
From: Neil Booth @ 2001-12-16 15:17 UTC (permalink / raw)
To: Kaveh R. Ghazi; +Cc: gcc-bugs, gcc
neil wrote:-
> The others convert the unsigned operand to signed, and therefore the
> result of the subtraction is signed.
Ignore that last sentence; I didn't read your examples closely enough
8-)
Neil.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Strange sign-compare results
2001-12-16 17:59 Kaveh R. Ghazi
@ 2001-12-17 0:02 ` Neil Booth
0 siblings, 0 replies; 5+ messages in thread
From: Neil Booth @ 2001-12-17 0:02 UTC (permalink / raw)
To: Kaveh R. Ghazi; +Cc: gcc-bugs, gcc
Kaveh R. Ghazi wrote:-
> I'm not sure what you mean then. Would you say the behavior I
> observed is a bug or feature?
It is the behaviour the C standard requires.
Neil.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Strange sign-compare results
@ 2001-12-16 17:59 Kaveh R. Ghazi
2001-12-17 0:02 ` Neil Booth
0 siblings, 1 reply; 5+ messages in thread
From: Kaveh R. Ghazi @ 2001-12-16 17:59 UTC (permalink / raw)
To: neil; +Cc: gcc-bugs, gcc
> From: Neil Booth <neil@daikokuya.demon.co.uk>
>
> neil wrote:-
>
> > The others convert the unsigned operand to signed, and therefore the
> > result of the subtraction is signed.
>
> Ignore that last sentence; I didn't read your examples closely enough
> 8-)
> Neil.
I'm not sure what you mean then. Would you say the behavior I
observed is a bug or feature?
--Kaveh
--
Kaveh R. Ghazi Engagement Manager / Project Services
ghazi@caip.rutgers.edu Qwest Internet Solutions
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2001-12-17 7:28 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-16 13:46 Strange sign-compare results Kaveh R. Ghazi
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
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).