Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!mcsun!sunic!dkuug!harald.ruc.dk!jba From: jba@harald.ruc.dk (Jan B. Andersen) Newsgroups: comp.lang.c Subject: Re: How to write an 8-bit clean program Message-ID: <487@harald.UUCP> Date: 15 Feb 90 15:34:08 GMT References: <1990Feb10.151053.16702@is.uu.no> Organization: RUC - Roskilde University Center, Denmark Lines: 46 ra@is.uu.no (Robert Andersson) writes: >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. Formally speaking, no! As you point out yourself, we're talking about 8 bit character sets. This simply means, that all 8 bits are (potentially) used to represent a character. Of course, one may look upon those bits as an unsigned integer with values from 0 to 255. >Is it kosher to store these values in char variables? I should think so. As long as |char| is guaranteed to hold at least 8 bit, the compiler should be able to map any character constant into a unique value before storing it. >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"; I'll take your word for it, although I don't see way it should complain. >lint dislikes things like: > unsigned char buff[100]; > write(fd, buff, 100); Probably because |buff| was declared as |char *buff| in the header. It might be more correct to declare it as |void *buff|. >Opinions? Just my 0.25 kr. -- Jan B. Andersen ("SIMULA does it with CLASS")