[Interest] Signed return type of QIODevice::pos() - why?

Rutledge Shawn Shawn.Rutledge at theqtcompany.com
Thu Nov 13 15:48:19 CET 2014


On 13 Nov 2014, at 14:45, Rainer Wiesenfarth <Rainer_Wiesenfarth at Trimble.com> wrote:

> One of my colleagues just asked the rather philosophical question why the
> result of QFile::pos() - and thus QIODevice::pos() - is of type qint64 (and
> thus signed). He had expected an unsigned type, ideally size_t or offset_t.
> 
> I was unable to find a reason, but maybe someone on the list can step in?

git grep ftell in qtbase tells me that QT_FTELL is defined as ftello on some platforms and ftell on others.  And ftell uses a signed number, and uses -1 to indicate an error (so I would assume the error case is the reason for using a signed number, even though it halves the largest-representable offset).  But the man page says ftello does that too, so off_t must be also signed.  Apparently the reason off_t exists is so that you can force it to be 64-bit even on a 32-bit system by setting _FILE_OFFSET_BITS.


More information about the Interest mailing list