[TUHS] v7 K&R C

Ronald Natalie ron at ronnatalie.com
Sun May 17 07:55:50 AEST 2020


It would have to be something bigger than char because you need EOF (whatever it could be defined as) to be distinct from any character.  


> On May 16, 2020, at 2:45 PM, Richard Tobin <richard at inf.ed.ac.uk> wrote:
> 
>> The function prototype for getchar() is:    int getchar(void);
>> 
>> It returns an int, not a char.  In all likelihood this is specifically
>> *because* EOF is defined as -1.
> 
> It would have probably returned int anyway, because of the automatic
> promotion of char to int in expressions.  It was natural to declare
> functions returning char as int, if you bothered to declare them at
> all.  As K&R1 said:
> 
>  Since char promotes to int in expressions, there is no need
>  to declare functions that return char.
> 
> Similarly functions that might return short or float would normally
> return int or double; there aren't separate atof and atod functions
> for example.
> 
> -- Richard
> 
> -- 
> The University of Edinburgh is a charitable body, registered in
> Scotland, with registration number SC005336.
> 



More information about the TUHS mailing list