Follow Slashdot blog updates by subscribing to our blog RSS feed

 



Forgot your password?
typodupeerror
×

Comment Re:Confused (Score 1) 160

"unsigned int x = -3;" generates no compile errors or warnings.

This supports the point of the poster you were referring to. The code is correct, predictable, and generates no warnings.

If you don't believe me, listen to the creator of C++

C and C++ are different languages. The implicit conversion rules and the promotion rules are different in C++ to C. In C, unsigned types always promote to unsigned types. But in C++, unsigned types may promote to signed ones, if the value fits in the signed range.

Comment Re:Confused (Score 1) 160

In general, it's a good idea to used signed ints whenever possible.

Says who?

In C, signed ints have a whole lot of problems associated with representation and overflow. But unsigned ints have well-defined behaviour in every circumstance. They wrap around in case of overflow or an out-of-range assignment. You can safely test, set and reset individual bits.

With signed ints, you can raise a signal (triggering a signal handler, or aborting the program if there is no handler) if there is overflow or underflow. Using '^', '|' or '&' on signed values can trap due to creating an invalid representation (e.g. negative zero, or parity error).

Test: what is wrong with this code snippet (assuming the appropriate furniture)? Hint: it doesn't always print 0x82.
    char ch = 130; /* é in the traditional code page */
    printf("0x%x\n", (unsigned int)ch);

Comment Re:Then why the cooling? (Score 1) 367

As a former Alaskan I can tell you that glacialization has come back the last 3 years and summer temperatures are rapidly falling year after year. So climate != weather but 13 years of data is starting to make a case for a cooler climate regardless of increased CO2.

"global warming" doesn't meant that every point on the globe will warm up by the same amount. It could be that Alaska gets colder, but Brazil gets hotter by a larger amount, for example.

Slashdot Top Deals

PURGE COMPLETE.

Working...