g++ : "seek"ing before BOF- doesn't fail ?!!

Hello All:

I'm reading a binary file in reverse order, using a while loop condition testing on the good() method. I was expecting a false condition when the seek eventually went before the first record. However my tests with:
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5) kept right on going!?!? This surprised me. Based on the references I've looked at, I expected a false return.

Is my understanding of the method incorrect, or does it appear that the compiler has a bug? Below is a sample program that demonstrates the problem.

Any thoughts would be appreciated.

// compiled with gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
// g++ -o tester test.cpp

/* testIn contents (cut and paste line into "inFile" file)

rec1 rec2 rec3 rec4 rec5 rec6 rec7 rec8
*/

#include <cstring>
#include <fstream>
#include <iostream>

#define REC_SIZE 5
#define BACK_1_REC -REC_SIZE

using namespace std;

int main() {
char *filename="inFile";
int count = 0;
std::streampos position;
// open file to the end
ifstream inFile(filename, ios::in | ios::binary | ios::ate );
while ( inFile.good() )
{
position = inFile.tellg();
cout << " backup count= " << count << " position= " << position << endl;
if (count > 10) return -1;
count++;
// backup 1 rec using seekg
inFile.seekg ( BACK_1_REC, ios::cur );
}
cout << filename << "file not good " << count <<endl;
cout << "backup count= " << count << " last good position= " <<
position << endl;
return 0;
}
Seems I've answered my own question. I've just got access to a machine with Fedora installed. The compiler with fedora is: gcc version 4.3.0 20080428 (Red Hat 4.3.0-8) (GCC).

The test program runs as expected, and ends with good() returning false. So the problem has been fixed in a more recent g++ compiler.

Sorry for the noise. I hope someone else will benefit from this info.

Cheers!
Topic archived. No new replies allowed.