Forum Discussion
Altera_Forum
Honored Contributor
15 years agoEverything is just a number!
The C 'char' type is just a 8-bit number, you can think of the input/output as using base 256 where some of the values are impossible to type! In C all arithmetic on types smaller than 'int' is done by converting the value to 'int', doing the maths, then masking off the high bits if the value is saved to a char variable. char is usually signed. (This is probably because the pdp11 only had a sign-extending byte read!) This means that 'unsigned char' gets promoted to 'int' (not 'unsigned int') unless 'sizeof (int) == 1'.