Problem with fstream in gcc3.4.0 (directory reading allowed?)

Paolo Carlini pcarlini@suse.de
Fri Apr 16 09:28:00 GMT 2004


Karel Gardas wrote:

>I have problem with MICO's mkdepend utility which shows wrong behaviour
>compiled with gcc 3.4.0 20040415.
>
Hi Karel.

In short, the current behavior is completely right and you should just fix
the loop to
   
    while (inp.getline(rawline, sizeof(rawline)).good())

since you cannot safely assume that either getline succeeds or eof is
encountered.

The little longer answer (I think should be explained more clearly in a
FAQ entry, actually), is that gcc3.4 is much /better/ than 3.3.x at
telling *real* eof from errors. In this case, actually, since the dir
cannot be read the underlying filebuf::underflow throws an exception
(because the under-underlying ;) read syscall returns -1), doesn't return
simply eof: correct! Therefore, in turn, getline just fails.

Paolo.



More information about the Gcc mailing list