turn off unnecessary warning [message #262409] |
Fri, 01 August 2008 12:43  |
Eclipse User |
|
|
|
Originally posted by: samuelandjw.gmail.com
Hi! I'm a newcomer.
I just tried to compile a project without modifying the default
preference, but the compiler g++ warned me about the comparison between
signed and unsigned. This warning is quite annoying because I have a lot
of loops. I have searched through a lot of options and preferences in
Eclipse, but I have no idea how to turn it off.
thx
|
|
|
|
|
Re: turn off unnecessary warning [message #262515 is a reply to message #262417] |
Tue, 05 August 2008 04:15  |
Eclipse User |
|
|
|
Originally posted by: root.local.host
>> Sam wrote:
>>> Hi! I'm a newcomer.
>>>
>>> I just tried to compile a project without modifying the default
>>> preference, but the compiler g++ warned me about the comparison
>>> between signed and unsigned. This warning is quite annoying because I
>>> have a lot of loops. I have searched through a lot of options and
>>> preferences in Eclipse, but I have no idea how to turn it off.
Joe Fisher <jfisher@overstock.com> wrote in news:g6vpbu$8mn$1
@build.eclipse.org:
> This is a g++ warning, nothing related to eclipse
> essentially, using "int" is not preferred, but size_type or size_t (go
> figure)
> You can turn of this warning from g++ (google around for the -WXXX)
> I'm not sure if you can filter it using eclipse error parsers
You can set up filters in the problem view.
Or, you can use -Wno-sign compare to shut up the warnings.
Sam, perhaps you should review those warnings. Comparison of signed and
unsigned quantities is suspect, because the rules are different. In an
operation between a signed and an unsigned int (of the same size),
unsigned "wins" (the signed quantity is automatically converted to
unsigned) and the operation is performed as unsigned. This can lead to
surptising results (the code below prints "Whoops!") and surprise in
software is bad.
#include <stdio.h>
int main()
{
unsigned int u = 2;
int i = -3;
if ( i > u )
puts( "Whoops!" );
else
puts( "ok" );
return 0;
}
If your loops have an upper limit which is size_t (e.g. from strlen() or
some_STL_container.size()) then the loop variable should be size_t also.
Perhaps we are safe 99.99% of the time, but I'm working on a 600000-line
project where this would mean 60 bugs hidden in the code.
I'm sticking to -Wall -pedantic -Wextra -Werror :)
--
Life is complex, with real and imaginary parts.
|
|
|
Powered by
FUDForum. Page generated in 0.12677 seconds