bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] avoid -Wsign-compare warnings


From: Pádraig Brady
Subject: Re: [PATCH] avoid -Wsign-compare warnings
Date: Fri, 11 Jul 2008 12:23:23 +0100
User-agent: Thunderbird 2.0.0.6 (X11/20071008)

Pádraig Brady wrote:
> I noticed Jim fixed a couple obvious
> issues highlighted by the -Wsigned-compare gcc option
> we were talking about a few days ago.
> 
> The attached patch silences all other instances,
> so that this option may be used to help find these
> hard to spot errors, when they're introduced in future.
> 
> Note this patch is just for comment at this stage.
> Also note it is not tested on 64 bit.

Thinking more about this, shows a lot of casts are
to address the gcc warning:
"signed and unsigned type in conditional expression"

I don't see why gcc is giving this warning, as
there is no comparison between signed and unsigned here.
For example in the following program compiled
with -Wsign-compare why does the second assignment
give a warning, while the first doesn't?

#include <stdio.h>
#include <limits.h>

int main(void)
{
    int i=0;
    unsigned u=UINT_MAX;

    if (u)  i = u; /* no warning */
    i = u ? u : i; /* warning with -Wsign-compare */

    printf("%d\n", i);

    return 0;
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]