This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch, fortran] Use getc/putc instead of fgetc/fputc


Hi,

Janne Blomqvist wrote:
> the attached patch converts the gfortran frontend to use getc/putc
> instead of fgetc/fputc.
For those who wonder like me what the difference are. (Quote from IEEE
1003.1-2001 - also known as POSIX 2001 or SUSv3; should be also in the C
standard):

"DESCRIPTION: The getc() function shall be equivalent to fgetc() ,
except that if it is implemented as a macro it may evaluate stream more
than once, so the argument should never be an expression with side effects."

"APPLICATION USAGE (informative only):
If the integer value returned by getc() 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.
Since it may be implemented as a macro, getc() may treat incorrectly a
stream argument  with  side  effects.  In  particular, getc(*f++)  does 
not  necessarily  work as expected.  Therefore, use of this function
should be preceded by "#undef getc" in such situations; fgetc() could
also be used."

As we don't seem to have expressions with side effects, there should be
no problem with getc. On my Linux getc indeed is a macro,
#define getc(_fp) _IO_getc (_fp)
though I don't know what is the difference between _IO_getc and fgetc.

I think the change is ok, but I did not review the patch (yet?).

Tobias


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]