Well, time for some explanation.

if (-1 < 10U) {
    foo();
} else {
    bar();
}

Answer: bar() (on most compilers. see below.). Why? According to ISO C++ 1998, section 5.9, binary operators promote operands until they are the same type. unsigned int is higher up in this heirarchy of types, so it is preferred over signed int. So -1 is converted to an unsigned int. How is it converted? Well, since -1 is outside of the range of unsigned int, the converted value is implementation defined (4.7.3). Technically, either foo() or bar() could be called. However, in *most* implementations -- that is, two's complement -- the bit pattern doesn't change. So -1 becomes the largest possible unsigned integer (0xFFFFFFFF if sizeof(int) == 4), which is clearly larger than 10.

And this is why most compilers warn you about comparisons between signed and unsigned integers! Heed them!

Here's a question I don't know the answer to: How do you initialize a signed (32-bit) integer to its smallest possible value in a standard way?

int smallest = -0x80000000;

VC7.1 gives a warning here because 0x80000000 doesn't fit in a signed int, so it becomes unsigned. However! You then apply the unary negation operator to an unsigned int, giving something that doesn't fit in the unsigned range! How would you do it on a platform that doesn't use two's complement?

And now for something completely different... (I like to wear women's panties!)

I'm trying to get all my Livejournal friends' locations plotted on a map - please add your location starting with this form.
Username:
(Then get your friends to!)

Sucks to XHTML 1.0 Strict-ify those LJ things...