A
Alex Vinokur
Method istream::readsome() behaves in a different way
with two different compilers: g++ and Microsoft C++.
What is reason for that?
Which compiler is correct? It seems that g++ is.
------ File xxx.cpp ------
#include <iostream>
#include <fstream>
#include <cassert>
using namespace std;
void foo()
{
char cbuffer[8];
streamsize len;
ifstream infile ("foo");
assert (infile);
assert (infile.is_open());
int i = 0;
do
{
len = infile.readsome (cbuffer, sizeof(cbuffer) - 1);
cout << "i = " << ++i << " : " << len << " " << sizeof(cbuffer) << endl;
cout << "<"; cout.write(cbuffer, len); cout << ">";
cout << "\n";
} while (len);
}
int main()
{
foo();
return 0;
}
--------------------------
------ Data file: foo ------
ABCDEFGHIK
abcdefghik
----------------------------
------ g++: Compilation & Run ------
// g++ 3.3.3
$ g++ xxx.cpp
$ a
i = 1 : 7 8
<ABCDEFG>
i = 2 : 7 8
<HIK
abc>
i = 3 : 7 8
<defghik>
i = 4 : 1 8
<i = 5 : 0 8
<>
------------------------------------
------ Microsoft C++: Compilation & Run ------
// Microsoft C++ 13.00.9466
$ cl /EHcs xxx.cpp
$ xxx
i = 1 : 0 8
<>
with two different compilers: g++ and Microsoft C++.
What is reason for that?
Which compiler is correct? It seems that g++ is.
------ File xxx.cpp ------
#include <iostream>
#include <fstream>
#include <cassert>
using namespace std;
void foo()
{
char cbuffer[8];
streamsize len;
ifstream infile ("foo");
assert (infile);
assert (infile.is_open());
int i = 0;
do
{
len = infile.readsome (cbuffer, sizeof(cbuffer) - 1);
cout << "i = " << ++i << " : " << len << " " << sizeof(cbuffer) << endl;
cout << "<"; cout.write(cbuffer, len); cout << ">";
cout << "\n";
} while (len);
}
int main()
{
foo();
return 0;
}
--------------------------
------ Data file: foo ------
ABCDEFGHIK
abcdefghik
----------------------------
------ g++: Compilation & Run ------
// g++ 3.3.3
$ g++ xxx.cpp
$ a
i = 1 : 7 8
<ABCDEFG>
i = 2 : 7 8
<HIK
abc>
i = 3 : 7 8
<defghik>
i = 4 : 1 8
<i = 5 : 0 8
<>
------------------------------------
------ Microsoft C++: Compilation & Run ------
// Microsoft C++ 13.00.9466
$ cl /EHcs xxx.cpp
$ xxx
i = 1 : 0 8
<>