Difference between char and unsigned char

Joseph Yip ycy at walt.cc.utexas.edu
Thu Jul 19 07:44:59 AEST 1990


Hi,

The char and  unsigned  char problem has been with me for a long time. I
know char represents 7 bits ASCII and unsigned char works with 8-bit.
Most of UNIX string functions (strcpy, strcmp,...). malloc() also
returns *char, not *unsigned char. 

Some systems have char defaulted to 8-bit. Other require you to declare
explicitly as unsigned char.

If I pass a unsigned char pointer to a function that expects a char
pointer, e.g. 

int foo( char *p);
...
unsigned char *buf;
a = foo(buf);

will there be a problem? Will the foo() mask off my 7th-bit?

You know I hate writing the same system library functions where the
only difference is the 7th-bit. 

If I am using ANSI C, the compiler will give me warnings or errors because
of the type mismatch!

Thank you

- Joseph Yip

Email: joseph at zeus.ee.utexas.edu



More information about the Comp.lang.c mailing list