g++ (or libstdc++ to be more exact) failed on the following simple testcase:
#include <iostream> #include <fstream> #include <cstdlib> int main() { try { const size_t bufsize = 2252778560; char* buf = new char[bufsize]; std::memset(buf, 0x22, bufsize); std::ofstream o("test.data"); o.write(buf, bufsize); if (o.fail()) { std::cerr << " write failed, rdstate: " << o.rdstate() << std::endl; if (o.bad()) { std::cerr << "bad\n"; } } } catch (...) { std::cerr << "exception!\n"; } } output of the program : ./a.out write failed, rdstate: 1 bad when it was compiled with g++ 4.1.2 with g++ 3.2.3 the test works fine sample compiler invocation: /gcc/v4.1.2p1/bin/g++ -m64 test_write.cpp -- Summary: file stream error writing large buffers Product: gcc Version: 4.1.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: satyaakam at yahoo dot co dot in http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32916