Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore 'comparison between signed and unsigned integer expressions'?

Tags:

Can anybody please tell me which flag I have to use in order to make gcc ignore the 'comparison between signed and unsigned integer expressions' warning message.

like image 736
Andrei Avatar asked Dec 07 '10 14:12

Andrei


People also ask

Can we compare signed int with unsigned int?

while comparing a>b where a is unsigned int type and b is int type, b is type casted to unsigned int so, signed int value -1 is converted into MAX value of unsigned**(range: 0 to (2^32)-1 )** Thus, a>b i.e., (1000>4294967296) becomes false. Hence else loop printf("a is SMALL!

Is it suggested to compare signed and unsigned numbers in C ++?

Sure, comparisons between signed and unsigned would be slower, but their result would be more correct in some sense. @Nawaz Your bottom line conclusion is incorrect, unfortunately: if the signed type can contain the unsigned type, the unsigned will be converted to the signed type and not the opposite.

What's the difference between a signed and an unsigned byte?

The term "unsigned" in computer programming indicates a variable that can hold only positive numbers. The term "signed" in computer code indicates that a variable can hold negative and positive values. The property can be applied to most of the numeric data types including int, char, short and long.

What are signed and unsigned integers?

A signed integer is a 32-bit datum that encodes an integer in the range [-2147483648 to 2147483647]. An unsigned integer is a 32-bit datum that encodes a nonnegative integer in the range [0 to 4294967295]. The signed integer is represented in twos complement notation.


2 Answers

gcc -Wno-sign-compare

But you should really fix the comparison it's warning you about anyway.

like image 191
robert Avatar answered Nov 10 '22 03:11

robert


Here's what worked for me, using the gcc compiler in Code::Blocks. In the compiler settings, click the "Compiler Settings" tab, then choose "Other Compiler Options. Type in -Wno-sign-compare The warning -Wsign-compare can be negated by adding "-Wno" as a prefix. In fact warnings can be ignored by adding -Wno- to the warning code.

like image 43
the_architect Avatar answered Nov 10 '22 03:11

the_architect