pt*****@hiperfe ct.com (Ptp) wrote in message news:<48******* *@hiperfect.com >...
is there a integer data type of one byte in gcc?
If gcc is a conformant C compiler (and it isn't always), it has three
types guaranteed to be at least eight bits wide: char, unsigned char,
and signed char.
What's the difference between signed and unsigned? One type can hold a
sign and has been modified in an implementation-specified way to do
it, the other cannot hold a sign and has behavior more stringently
defined by the Standard in the various edge cases. One of the edge
cases is wrap-around: If you do
#include <limits.h>
unsigned char foo(void)
{
unsigned char i = UCHAR_MAX;
i++;
return(i);
}
the return value from foo() is defined (it is 0). If, however, you do
#include <limits.h>
signed char bar(void)
{
signed char i = CHAR_MAX;
i++;
return(i);
}
the return value from bar() is implementation-dependent and is allowed
to be a trap representation (that is, one that sends the machine into
a tizzy).
So, if you want to treat your at-least-eight-bits-wide values as an
unsigned type with a strictly defined behavior in case of overflow,
use unsigned char. If you need to hold a sign, use signed char or
char.