This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: no warning on mixing unsigned and signed
- From: Peter Barada <pbarada at mail dot wm dot sps dot mot dot com>
- To: Peter dot Barada at motorola dot com
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 19 Mar 2002 18:54:18 -0500
- Subject: Re: no warning on mixing unsigned and signed
- References: <200203192349.g2JNngW20896@hyper.wm.sps.mot.com>
>I been alerted to a bug in gcc-3.0.4 and 2.96(yeah, I know its a
>release from RH, but I don't have a 2.95.3 version handy), the
>following code when built using '-O -Wall' doesn't warn that the
>comparison can not be false, and converts 'foo' into an empty function
>since (a-b) can not be negative:
>
>extern void bar(void);
>void foo(int a, unsigned int b)
>{
> if ((a - b) < 0)
> bar();
>}
>
>If a is unsigned, or the expression is (a < 0) the results are the same...
Arrrggghh; fat fingered that badly. It should've been:
I been alerted to a bug in gcc-3.0.4 and 2.96(yeah, I know its a
release from RH, but I don't have a 2.95.3 version handy), the
following code when built using '-O -Wall' doesn't warn that the
comparison can not be *true*, and converts 'foo' into an empty function
since (a-b) can not be negative:
extern void bar(void);
void foo(int a, unsigned int b)
{
if ((a - b) < 0)
bar();
}
If a is unsigned, *and if* the expression is (a < 0) the results are
the same...
--
Peter Barada Peter.Barada@motorola.com
Wizard 781-852-2768 (direct)
WaveMark Solutions(wholly owned by Motorola) 781-270-0193 (fax)