← Back to context

Comment by anonnon

9 days ago

> The return type of fgetc() is `int` and not `char`. This example will not differentiate between end-of-file in input versus reading 0xff

Be aware that character literals in c, e.g., 'f' or 'A', have type int for probably this reason. From the ANSI C89 spec:

> An integer character constant has type int. The value of an integer character constant containing a single character that maps into a member of the basic execution character set is the numerical value of the representation of the mapped character interpreted as an integer.

However, in C++, they have type char.