This is the mail archive of the gcc-bugs@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]

Re: a wierd file pointer error?


Not so obvious, but my error. This reply from someone on the glibc
bugs list. Had better do a more thorough job of reading TFM :-) 
jasper.

===============================================================

>   I posted this to the gcc list. It was suggested there that
>   this could be a glibc/kernel error.

Nope, it is a bug in your program.  The ISO C standard (or at least
the draft that I have) says:

       [#6]  When  a  file  is  opened with update mode ('+' as the
       second or third character in the above list of mode argument
       values),  both  input  and  output  may  be performed on the
       associated stream.  However, output shall  not  be  directly
       followed  by input without an intervening call to the fflush
       function or to a file positioning function (fseek,  fsetpos,
       or  rewind),  and  input  shall  not be directly followed by
       output without an intervening call  to  a  file  positioning
       function, unless the input operation encounters end-of-file.
       Opening (or creating) a  text  file  with  update  mode  may
       instead   open   (or   create)   a  binary  stream  in  some
       implementations.

The ftell() operation somehow flushes the stream (or is it a file
positioning function?), but if you don't call it you are doing inpu
right after output which is a no-no.

Mark

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