https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66773

--- Comment #15 from Segher Boessenkool <segher at gcc dot gnu.org> ---
(In reply to Daniel Marjamäki from comment #12)
> So, how would you fix the warning for `f`? Many programmers would "fix" it
> with a cast.
> 
> Assuming that `s` and `u` can have arbitrary values, here is the proper code:
> 
> void f(long s, unsigned long u) { if (s >= 0 && s == u) g(); }
> 
> For this correct code, gcc warns.

A much better fix is

void f1(long s, unsigned long u) { unsigned long su = s; if (su == u) g(); }

which makes it rather explicit what is going on.

Still much better is to not mixed signedness in types at all.

Reply via email to