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 chars. 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. -Peter 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.