12 Mar 2010 12:06
-Wsign-compare issues
Iain Hibbert <plunky <at> rya-online.net>
2010-03-12 11:06:01 GMT
2010-03-12 11:06:01 GMT
Hi,
Not sure if this is an issue or not. using -Wsign-compare with the
following code on with pcc/i386 produces two errors whereas I can't get
gcc to produce an error about it
void
test(int i, unsigned short u)
{
if (i == u)
;
if (i == (u * 3))
;
if (i == (u * -2))
;
}
I think in the first case, u is promoted to an int because all short
values can be represented by int, and this doesn't produce an error.
In the second case, u is promoted to an unsigned int during the
arithmetic, but then it cannot be promoted to an int since it might not
fit. I'm not completely sure if this is a bug or an implementation detail.
In the third case I think the same happens even though the multiplier is
explicitly signed and is more likely to be a bug.
I'm not sure if this is intentional or not, but because gcc does it
differently I'm not sure whether to just start adding casts to code that
(Continue reading)
Not having gcc compat would mean that the
first thing you
need to do is to rewrite many of the system header files on your OS, and
then change all
gcc-isms that are in the programs you may want to compile. This is
usually not what people
want to do when testing another compiler.
> Or better said: why can't GCC compatibility be disabled?
>
Laziness. gcc compat require changes to the yacc code, which is not
easy to preprocess.
Also, some of the gcc extensions are needed to make the compiler usable
on a specific
target, and instead of inventing it in a new way I just stick with the
gcc way.
-- Ragge
RSS Feed