How to write an 8-bit clean program

Robert Andersson ra at is.uu.no
Sun Feb 11 02:10:53 AEST 1990


An important subject for us Europeans with all our strange character sets.
But, what is the best way to do it?

Of course, using the eight bit as a flag, assuming that letters range from
'A' to 'Z' etc. are well known things to avoid, and that is not what
I would like to discuss. What I would like is to hear other peoples opinion 
on the signed/unsigned char issue.

The type 'char' as defined in C on some implementations range from 
-127 to 128, on others from 0 to 255. The rest of this message assumes
the compiler has signed chars as a default.

In an 8-bit set some character will have values > 128.
Is it kosher to store these values in char variables?

Suppose you do it, then as long as you simply use char variables in
simple assignments/test or as buffers, all is probably OK. As soon as
you use the variable in arithmetic expressions or assigments to other
types things become more muddy.

So, the better way to do it might be to change all char variables in
your program to unsigned char? But that opens another can of worms.
Many compilers spit out warnings for expression like:
	unsigned char *junk = "morejunk";
lint dislikes things like:
	unsigned char buff[100];
	write(fd, buff, 100);
Of course you could add casts in all those places, but is sort of doesn't
'feel' right to do that.

It seems you lose in either case.
Opinions?
-- 
Robert Andersson, International Systems A/S, Oslo, Norway.
Internet:         ra at is.uu.no
UUCP:             ...!{uunet,mcsun,ifi}!is.uu.no!ra



More information about the Comp.lang.c mailing list