I have trouble understanding the choice of C++ types used regarding file size and buffer size in IReadFile and IWriteFile.
It is clear to me why the amount of bytes to write or read must be given as an unsigned integer, but I fail to understand why the amount of bytes written or read will be returned as a signed integer. Especially troubling to me is that the actual file size is returned as a signed integer.
So here are my questions:
- Is it really possible to have irr::io::IWriteFile::write(...), irr::io::IReadFile::read(...) and irr::io::IReadFile::getSize() returning negative byte amounts?
- Wouldn't it be better to have irr::io::IReadFile::getSize() returning an unsigned long instead, so that I do not have to static_cast when I want to read a whole file?
Code: Select all
irr::io::IReadFile* file = fileSystem_->createAndOpenFile( "fileName" );
irr::u32 size = static_cast<irr::u32>( file->getSize() ); // I wish I would not have to cast here, it seems not logical to me
irr::core::array<irr::c8> buffer( size + 4 ); // +4 to paranoia
file->read( buffer.pointer(), size );
file->drop();
Please enlighten me. Thank you in advance!
Best Regards,
dixx