lkml.org 
[lkml]   [2003]   [Feb]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] s390 (7/13): gcc 3.3 adaptions.
On Mon, 24 Feb 2003, Linus Torvalds wrote:

>
> On Mon, 24 Feb 2003, Richard B. Johnson wrote:
> >
> > I think you must keep these warnings in! There are many bugs
> > that these uncover uncluding loops that don't terminate correctly
> > but seem to work for "most all" cases. These are the hard-to-find
> > bugs that hit you six months after release.
>
> At least historically gcc has been so f*cking bad at the "unsigned vs
> signed" warnings that they are totally useless.
>
> Maybe things are better in gcc-3.3.
>
> Maybe not.
>
>
> > size_t i;
> >
> > while((i = do_forever()) > 0)
> > ;
> >
> > ... do_forever() finally errors out and returns -1 stuck(forever).
>
> Does gcc still warn about things like
>
> #define COUNT (sizeof(array)/sizeof(element))
>
> int i;
> for (i = 0; i < COUNT; i++)
> ...
>
> where COUNT is obviously unsigned (because sizeof is size_t and thus
> unsigned)?
>
> Gcc used to complain about things like that, which is a FUCKING DISASTER.
>
> Any compiler that complains about the above should be shot in the head,
> and the warning should be killed.
>
> Linus
>

Well yes. And it's correct. Variable `i' in the following code
should be a 'size_t'.

Script started on Mon Feb 24 16:23:19 2003
# cat xxx.c
#define ArraySize(a) (sizeof(a) / sizeof(a[0]))
int foo[12] = {0,};
int count()
{
int i;
for(i=0; i< ArraySize(foo); i++)
;
return i;
}

# gcc -Wall -Wsign-compare -c -o xxx.o xxx.c
xxx.c: In function `count':
xxx.c:11: warning: comparison between signed and unsigned
# exit
exit
Script done on Mon Feb 24 16:23:50 2003

... and we all know that it's dumb to do:
for(i=0; i< (int) ArraySize(foo); i++)
... just to placate a compiler. But the compiler did find what
could-have-been a real problem so the compiler is, indeed, correct.

Maybe what is needed is -Wsign-compare and -Wsign-strict, where
-Wsign-compare warns of obvious errors that could cause continuous
loops, etc., and -Wsign-strict acts like the current -Wsign-compare.
I agree that the current -Wsign-compare is way too strict for the
usual coding style where most int compares are "don't care" things
that are not worth casts.

Cheers,
Dick Johnson
Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).
Why is the government concerned about the lunatic fringe? Think about it.


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:33    [W:0.085 / U:0.012 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site