This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
istream
- To: gcc-bugs at gcc dot gnu dot org
- Subject: istream
- From: Frederic Tran_Minh <ftran at sophia dot inria dot fr>
- Date: Fri, 24 Aug 2001 18:03:40 +0200 (MET DST)
hi,
this is perhaps not a bug, but at least a different behavior between
gcc 2.95 and gcc 3.0, and you perhaps can give me a hint for porting.
the sample attached program makes 2 tests reading n bytes from
a file ;
test1 : file == std::cin fails on gcc3, succeeds on gcc2.95
test2 : file is a std::ifstream, succeeds on both.
Unfortunately I cannot attach you the input file since it's a 5769604
bytes confidential file, but **the same file** is used as input in **all**
cases.
you will find as attached files
1/ the bug diagnostic bugrep00
2/ the sample source file test_istream.cc
Fred
To: gcc-bugs@gcc.gnu.org
Subject: istream
hi,
this is perhaps not a bug, but at least a different behavior between
gcc 2.95 and gcc 3.0, and you perhaps can give me a hint for porting.
the sample attached program makes 2 tests reading n bytes from
a file ;
test1 : file == std::cin fails on gcc3, succeeds on gcc2.95
test2 : file is a std::ifstream, succeeds on both.
Unfortunately I cannot attach you the input file since it's a 5769604 bytes
confidential file, but **the same file** is used as input in **all** cases.
Platform 1
----------
> uname -a
SunOS gollum 5.6 Generic_105181-26 sun4u sparc SUNW,Ultra-5_10
> g++ -v
Reading specs from /usr/local/gcc/lib/gcc-lib/sparc-sun-solaris2.6/2.95.3/specs
gcc version 2.95.3 20010315 (release)
Configuration/Compilation of gcc/g++ : unknown
Compilation command line :
> g++ -o test_istream test_istream.cc
Input file :
> ls -l $IMDIR/NewRef/orlycut_ref1m_03_60_sr.cv.ima
-rw-r--r-- 1 ftran ariana 5769604 May 22 15:35 ../Images/Images_Astrium/NewRef/orlycut_ref1m_03_60_sr.cv.ima
TEST1 (#define TEST1 #undef TEST2)
Command line :
> test_istream 5750388 < $IMDIR/NewRef/orlycut_ref1m_03_60_sr.cv.ima
Output :
Reading 5750388 chars ...
Streampos = 0
Read 5750388 chars
Streampos = 5750388
Diagnostic : OK
TEST2 (#undef TEST1 #define TEST2)
Command line :
> test_istream 5750388 $IMDIR/NewRef/orlycut_ref1m_03_60_sr.cv.ima
Output
Reading 5750388 chars ...
Streampos = 0
Read 5750388 chars
Streampos = 5750388
Diagnostic: OK
Platform 2
----------
> uname -a
SunOS fermi 5.6 Generic_105181-25 sun4u sparc SUNW,Ultra-80
> g++ -v
Reading specs from /lpps04/simage/ARIANA/Soft/gnu/lib/gcc-lib/sparc-sun-solaris2.6/3.0.1/specs
Configured with: /lpps04/simage/ARIANA/Soft/gnu/packages/gcc-3.0.1/configure --prefix=/lpps04/simage/ARIANA/Soft/gnu
Thread model: posix
gcc version 3.0.1
Configuration/Compilation of gcc/g++ :
srcdir/configure --prefix=/lpps04/simage/ARIANA/Soft/gnu
make bootstrap
(no modification of gcc/g++ source)
Compilation command line :
> g++ -o test_istream test_istream.cc
Input file :
> ls -l $IMDIR/NewRef/orlycut_ref1m_03_60_sr.cv.ima
-rw-r--r-- 1 ftran ariana 5769604 May 22 15:35 ../Images/Images_Astrium/NewRef/orlycut_ref1m_03_60_sr.cv.ima
TEST1 (#define TEST1 #undef TEST2)
Command line :
> test_istream 5750388 < $IMDIR/NewRef/orlycut_ref1m_03_60_sr.cv.ima
Output :
Reading 5750388 chars ...
Streampos = 0
Read 5748727 chars
Streampos = -1
Diagnostic : fails before real end of file
TEST2 (#undef TEST1 #define TEST2)
Command line :
> test_istream 5750388 $IMDIR/NewRef/orlycut_ref1m_03_60_sr.cv.ima
Output
Reading 5750388 chars ...
Streampos = 0
Read 5750388 chars
Streampos = 5750388
Diagnostic: OK
#include <iostream>
#include <cassert>
#include <cstdlib>
//#undef TEST1
#define TEST2
#ifdef TEST1
main(int argc, char **argv) {
assert(argc>1);
unsigned int n = atoi(argv[1]);
char *X = new char[n];
std::cerr << "Reading " << n<< " chars ..." << std::endl;
std::cerr << " Streampos = " << std::cin.tellg() << std::endl;
std::cin.read(X,n);
std::cerr << " Read " << std::cin.gcount() << " chars" << std::endl;
std::cerr << " Streampos = " << std::cin.tellg() << std::endl;
delete [] X;
return 0;
}
#endif
#ifdef TEST2
#include <fstream>
main(int argc, char **argv) {
assert(argc>2);
unsigned int n = atoi(argv[1]);
char *X = new char[n];
std::ifstream stream(argv[2]);
std::cerr << "Reading " << n<< " chars ..." << std::endl;
std::cerr << " Streampos = " << stream.tellg() << std::endl;
stream.read(X,n);
std::cerr << " Read " << stream.gcount() << " chars" << std::endl;
std::cerr << " Streampos = " << stream.tellg() << std::endl;
stream.close();
delete [] X;
return 0;
}
#endif