public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/40732]  New: fstream get/put pointers have unexpected positions
@ 2009-07-13 14:23 elizbus at yahoo dot com
  2009-07-13 14:34 ` [Bug libstdc++/40732] " paolo dot carlini at oracle dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: elizbus at yahoo dot com @ 2009-07-13 14:23 UTC (permalink / raw)
  To: gcc-bugs

My understanding is that with fstream, get and put pointers move together.  
Therefore expect output of following to be aabbc1234, output is actually aabbc.
This had expected result with 3.3.1, unexpected result with 3.4.4.


#include <fstream>
using namespace std;
int main(int argc, char* argv[])
{
fstream myStream;
myStream.open("myTestFile.out", ios_base::in | ios_base::out | ios::trunc);
// write "aabbc" to file
myStream.put('a');
myStream.put('a');
myStream << "b";
myStream << "b";
myStream << "c";
//rewind
myStream.seekg(0);
char c;
//skip over data
for (int i=0; i < 5; i++) {
myStream.get(c);
}
// append 1234 to file
myStream << "1234\n";
myStream.close();
return 0;
}


Configured with: ./configure --prefix=/usr/local/gcc-3.4.4
Thread model: posix
gcc version 3.4.4


-- 
           Summary: fstream get/put pointers have unexpected positions
           Product: gcc
           Version: 3.4.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: elizbus at yahoo dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40732


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libstdc++/40732] fstream get/put pointers have unexpected positions
  2009-07-13 14:23 [Bug libstdc++/40732] New: fstream get/put pointers have unexpected positions elizbus at yahoo dot com
@ 2009-07-13 14:34 ` paolo dot carlini at oracle dot com
  2009-07-13 17:24 ` elizbus at yahoo dot com
  2009-07-13 19:59 ` paolo dot carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-07-13 14:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from paolo dot carlini at oracle dot com  2009-07-13 14:33 -------
Your assumption is wrong, in the sense that nothing in the Standard mandates it
(likewise in C, for plain C streams, by the way) and in fact most, if not all,
current good performing implementation do not satisfy it.


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40732


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libstdc++/40732] fstream get/put pointers have unexpected positions
  2009-07-13 14:23 [Bug libstdc++/40732] New: fstream get/put pointers have unexpected positions elizbus at yahoo dot com
  2009-07-13 14:34 ` [Bug libstdc++/40732] " paolo dot carlini at oracle dot com
@ 2009-07-13 17:24 ` elizbus at yahoo dot com
  2009-07-13 19:59 ` paolo dot carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: elizbus at yahoo dot com @ 2009-07-13 17:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from elizbus at yahoo dot com  2009-07-13 17:24 -------
(In reply to comment #1)
> Your assumption is wrong, in the sense that nothing in the Standard mandates it
> (likewise in C, for plain C streams, by the way) and in fact most, if not all,
> current good performing implementation do not satisfy it.

If I were to add a call to tellg() prior to appending additional data to the
stream, the put pointer is now at the correct location and the output file now
has all ten characters written to it, and not five.  If the pointers are
independent, then this should not happen.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40732


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libstdc++/40732] fstream get/put pointers have unexpected positions
  2009-07-13 14:23 [Bug libstdc++/40732] New: fstream get/put pointers have unexpected positions elizbus at yahoo dot com
  2009-07-13 14:34 ` [Bug libstdc++/40732] " paolo dot carlini at oracle dot com
  2009-07-13 17:24 ` elizbus at yahoo dot com
@ 2009-07-13 19:59 ` paolo dot carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-07-13 19:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from paolo dot carlini at oracle dot com  2009-07-13 19:59 -------
The pointers are in some sense independent, but in this exact technical sense:
a seekg ends up calling the seekoff fstream virtual and therefore the mode
becomes 'uncommitted', neither read mode neither write mode. Successive writes
are therefore well defined and proceed exactly from the place where the last
read took place. Alternately, you could achieve the same net effect by stopping
reading when end of file is extracted: in C, and C++, this is a special case,
which also leads to 'uncommitted' mode, thus the following writes are well
defined - evidently in this case the user wants to append. But you can find
many testcases about all the various behaviors in the testsuite. Since this is
free software I also encourage you to browse the actual implementation: the
last special case, for example, is very clear toward the end of
basic_filebuf::underflow.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40732


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-07-13 19:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-13 14:23 [Bug libstdc++/40732] New: fstream get/put pointers have unexpected positions elizbus at yahoo dot com
2009-07-13 14:34 ` [Bug libstdc++/40732] " paolo dot carlini at oracle dot com
2009-07-13 17:24 ` elizbus at yahoo dot com
2009-07-13 19:59 ` paolo dot carlini at oracle dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).