http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47694
--- Comment #22 from Janne Blomqvist <jb at gcc dot gnu.org> 2011-02-24 15:08:00 UTC --- (In reply to comment #21) > (In reply to comment #20) > > + if (q == EOF) > > > > Does this always work? We have in "static inline int fbuf_getc (gfc_unit * > > u)": > > return (unsigned char) u->fbuf->buf[u->fbuf->pos++]; > > and "q" is "int". > > > > The issue I see is the following (quote from POSIX's fgetc(3p)): > > "If the integer value returned by fgetc() is stored into a variable of type > > char and then compared against the integer constant EOF, the comparison may > > never succeed, because sign-extension of a variable of type char on > > widening to > > integer is implementation-defined." > > You're missing the whole picture. The definition of fbuf_getc in fbuf.h is > > static inline int > fbuf_getc (gfc_unit * u) > { > if (u->fbuf->pos < u->fbuf->act) > return (unsigned char) u->fbuf->buf[u->fbuf->pos++]; > return fbuf_getc_refill (u); > } > > That is, the inlined fast path is for the case when there is data available in > the buffer. If there isn't data, it falls back to fbuf_getc_refill, where if > filling the buffer with more data fails EOF is returned, otherwise the next > character cast to unsigned char. That is, there is never some kind of EOF character in the buffer, rather EOF is a special error value which is returned when there is no more data available.