They are twos complement, *if they exist*. On platforms with
ones complement, or 9 bit bytes, you're toast.
One of the advantages of using them is that if the platform
doesn't support what you require, your code won't compile.
Whereas if you just use char, you're most likely to get some
strange behavior at run-time. (And of course, there's no
requirement that uint8_t be two's complement
.)
They are all the same size on a given platform. Was that your
question?
The best way to be platform independent is to define the
transport format separately. They you have to implement this
on each platform, in a platform dependent way.
Or not. It does depend a bit on what you're streaming.
For integer values, the standard guarantees that converting a
signed value to the corresponding unsigned type will result in
the bit pattern of 2's complement (assuming the value
fits---which is not guaranteed), e.g. on a 16 bit machine,
converting -1 to unsigned int always results in 0xFFFF,
regardless of the representation used for negative numbers.
(Note that compilers for machines which do not use 2's
complement may require a special option to be conformant in this
respect, since it means generating extra code to do the correct
conversion.) This means that regardless of the internal
representation, if the numeric value fits, you can always output
an integer in Internet format (four 8 bit bytes, high byte
first, 2's complement) by converting it to an unsigned long (to
be sure of having at least 32 bits), then outputting the four 8
bit blocks in the correct order, by shifting and masking.
Inputting is a bit trickier, since the results of converting an
unsigned integral type to a signed is implementation defined,
and may result in an implementation defined signal if the value
doesn't fit. Formally, I think you'd have to do something like:
if ( unsignedValue > 0x7FFFFFFF ) {
signedValue = ~ unsignedValue ;
signedValue = - signedValue ;
-- signedValue ;
}
(In practice, I use uint32_t and int32_t, memcpy'ing to do the
"conversion". Or just converting, if I know that only limited
portability is required, e.g. Sparc and PC, but nothing else.)