[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 Mon, Dec 31, 2001 at 01:33:37PM -0500, Colin Walters wrote:
> 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.

IMHO, this is a peculiar statement.  The type 'char' is best suited to
things that are characters or bytes.  For array indices, int tends to
be a better choice: most CPUs cannot read single bytes any faster than
machine words; compilers allocate registers at their full width; some
architectures (68K for proper sign extension) sometimes require extra
instructions in order to perform sub-word width math; careless
alignment can be a problem with sub-word values packed into
structures.  Obviously, a compelling reason for 'char' as an index is
when storing many of them, but in such a care must be taken to write
what you mean and declare unsigned-ed-ness when that is what you want.


Reply to: