I never understood why the standard would not use unsigned char there.
Because by the time the standard came around, it was too late. In pre-standard C it was normal to not include function declarations – in fact I’m not sure if function declarations were allowed / did anything in the 70s C compilers. WIthout a function declaration, every function parameter (and also return type) would undergo standard integer promotions, meaning a type smaller than int would be widened to an int. (You may notice this is the same rule as with varargs nowadays.)
Stdio debuted (as far as I know) in 1979’s version 7 Unix, so it was designed around this kind of no-function-declaration style of C programming. If the C89 standards process had been able to break backwards compatibility with pre-standard C, I’m sure they would have been redefined to be unsigned char.
This is the content I am here for. Perfect mix of nerdiness, whimsy and technical details. Kudos!
First love for
make
, thenperl
, and nowawk
. We’re having a retro appreciation week.Bitwise ops on signed integers in C is a headache.
This is a understatement. In practice the input would rarely be guaranteed to be in the safe range to avoid UB.
And the argument type of putchar/putc/fputc is such a lie. I never understood why the standard would not use unsigned char there.
Because by the time the standard came around, it was too late. In pre-standard C it was normal to not include function declarations – in fact I’m not sure if function declarations were allowed / did anything in the 70s C compilers. WIthout a function declaration, every function parameter (and also return type) would undergo standard integer promotions, meaning a type smaller than int would be widened to an int. (You may notice this is the same rule as with varargs nowadays.)
Stdio debuted (as far as I know) in 1979’s version 7 Unix, so it was designed around this kind of no-function-declaration style of C programming. If the C89 standards process had been able to break backwards compatibility with pre-standard C, I’m sure they would have been redefined to be unsigned char.