[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: at least 260 packages broken on arm, powerpc and s390 due to wrong assumption on char signedness

On 31 Dec 2001, Colin Walters wrote:

> > and there's a small possibility that char could be some weird wide
> > character thing, 
> No, the C standard guarantees that a char is exactly a single byte; i.e.
> sizeof(char) == 1.

I think he meant "wider than one would think"-character.  A char didn't
originally have to be 8 bits wide -- the first edition of K & R "The C
Programming Language" explicitly mentions an implementation with 9-bit

I think the newer standards say you have to use 8-bit chars but with some
sort of "cat flap" clause that allows exceptions if the platform is a
weird DSP or something like that.

> It can't be larger than 255 (precisely because it is limited to a single
> byte).

Careful - a byte is not always the same as an octet.

> The more I think about it, the more it makes sense to always explicitly
> declare all char variables as signed or unsigned; otherwise, you're just
> asking for latent bugs.

Not when you are using them for characters -- only if you are using them
as small integers.  Just be very careful when you perform arithmetics and
relations on chars.  It is often a better idea to use a macro or function
from the standard library.


Anxiety, n.:
        The first time you can't do it a second time.
Panic, n.:
        The second time you can't do it the first time.

Reply to: