No Compilation Warning...

Jim Wilson wilson@specifixinc.com
Thu Jun 24 22:43:00 GMT 2004


Manje Gowda S G wrote:
> 1) There is some fundamental reason behind this, I am not aware..., any light on this is greatly appreciated.

The real reason for this is probably "an accident of history".

However, K&R C and ISO C have different rules for promoting types when 
you mix types with different sizes and different signedness.  Thus it 
makes some sense to emit warnings by default in this case, as this will 
help catch problems in code that may have been written for a different 
version of the C language.  It makes no difference for this specific 
example, but in general it may make a difference.

There is also the problem that it is easy to type a number that is too 
large for a small type, like short, but that can't happen for int, as 
then you would have a parse error.  So it makes more sense to have range 
checks for types smaller than int than it does to have them for int.

> 2) STILL...,
> 	unsigned int s;
> 	if (0 <= s) {....}

If you use -Wextra, you will get a warning.  See the documentation. 
This is a different warning message than the one you get for shorts.
-- 
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com



More information about the Gcc mailing list