On 10/15/05, woodelf <bfranchuk at jetnet.ab.ca> wrote:
The most real non-portable C factor is everybody expects bytes to 8 bits
and CR,LF line endings are
a bitch. I think a character can be 7 or more bits, a int something bigger
like 16. ( As far as I know C never made it to a PDP8 ).
I'm not sure what you mean about CR-LF line endings being a problem for C.
For text files the character '\n' returns the appropriate ending, whether it
is CR-LF, CR, or LF. For binary files you shouldn't need to write carriage
returns.
Integral types in C aren't difficult. They are just flexible, and because
they are flexible, you need to know the rules.
A char needs to be able to hold at least 127 unique values which makes it at
least 7 bits with one allowed "non-unique" value (for example +0 and -0
allowed to have different bit patterns but compare equal, or a value can be
reserved for other purposes (signaling, I/O, etc)). That makes it a bit
different from the other integral types which are required to behave in
standard two's compliment fashion. Regardless of the number of bits or
machine words used to store a char, the size of a char is 1
(sizeof(char)==1). If you want to know the number of "bits" in a char,
there's always the CHAR_BIT macro. Whether char is unsigned or signed is
implementation dependent. If you need one or the other use "signed char" or
"unsigned char".
An int needs to hold at least 65536 unique values (-32768..32767) (16 bits).
I believe that it is required to be at least as large as a char. An unsigned
long needs to be able to hold the values between 0 and 65535. Arithmetic
must behave as if the numbers are stored as two's compliment [ (x | -1) ==
-1 , (x & -1) == x ]
A long needs to be at least 32 bits and must the at least as large as an
int.
The size of a pointer needs to be at least as large as an int. Pointers to
one type are not necessarily convertable to pointers to another type,
although all pointers can be cast to void *. Avoid converting pointers into
integral types. Do pointer math on pointers.