Why 'fputc' use an INT as its parameter instead of CHAR?

前端 未结 2 1069
悲哀的现实
悲哀的现实 2020-12-31 16:43

standard C lib:

int fputc(int c , FILE *stream);

And such behaviors occured many times, e.g:

    int putc(int c, FILE *str         


        
2条回答
  •  情书的邮戳
    2020-12-31 17:28

    No char parameters in K&R C

    One reason is that in early versions1 of C there were no char parameters.

    Yes, you could declare a parameter as char or float but it was considered int or double. Therefore, it would have, then, been somewhat misleading to document an interface as taking a char argument.

    I believe this is still true today for functions declared without prototypes, in order for it to be possible to interoperate with older code.


    1. Early, but still widespread. C was a quick success and became the first (and still, mostly, the only) widely successful systems programming language.

提交回复
热议问题