2008-05-26

signed or unsigned

I'm programing in C++ for years now and I still experience frequent surprises. Even on topics where I was dead sure.

Is an int signed or unsigned? The standard clearly says (section 3.9.1.2)

There are four signed integer types: "signed char", "short int", "int", and "long int."
So writing just int means the same as signed int which is as expected.

And here is the surprise: this is not always true. Section 9.6.3 says:

It is implementation-defined whether a plain (neither explicitly signed nor unsigned) char, short, int or long bit-field is signed or unsigned.

Unbelievable... It would have been too easy otherwise, I guess...

Thanks, Roker


Posted by Alexander Bernauer | Permanent Link | Categories: C++