Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Behavior of istream::read() and istream::gcount()

807575Feb 20 2003 — edited Feb 20 2003
We downloaded a patch for the Forte 6 compiler, and some of our code is no longer doing what we expect it to as far as istream::read is concerned.

We have an example program that shows the behavior:

int main(int argc, char **argv)
{
ifstream fin(argv[1]);
char buf[1024];
fin.read(buf, 4);
while( fin.gcount() > 0 )
{
fin.read(buf, 4);
}

cout << "Finished!" << endl;
}

In our previous incantation of the compiler, this worked: When EOF was reached, fin.gcount() returned 0, and we exited as expected. However, since we patched Forte this no longer works -- namely, when EOF is reached, fin.gcount remains equal to what the last "good read" returned, so it stays in an infinite loop.

I know that we can work around this by writing the loop to check for fin.good(), but that will require quite a bit of work on our behalf because find.good() == false on the last partial read (which does have good data).

Should I be able to count on istream::gcount() returning to zero? If so, we need to repatch our compiler (and that's ok); if not, then we need to do some work.

$ CC -version
Sun Workshop 6 update 2 C++ 5.3 patch 111685-10 2002/09/16

TIA!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 20 2003
Added on Feb 20 2003
1 comment
409 views