This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: constant signed/unsigned comparison warning


Matthias Urlichs wrote:

> And because GCC knows how to figure out the size of the struct, but then
> forgets to check if the high bit of that size is set (otherwise you cannot
> run into a problem in the first place).

The problem is that, for all the compiler knows, this might be
equivalent to

    int i = random_func_which_returns_minus_10000();

    if (i == -1) {
	...
    }
    else if (i < sizeof(foo)) {
	...
    }

This case CAN be a problem, since the second comparison would be false,
and this could very well be a thinko on the part of the programmer.
-- 
Thomas Koenig, Thomas.Koenig@ciw.uni-karlsruhe.de, ig25@dkauni2.bitnet.
The joy of engineering is to find a straight line on a double
logarithmic diagram.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]