Signed word lengths and indexes
Kagamin
spam at here.lot
Thu Jun 17 00:27:59 PDT 2010
Justin Spahr-Summers Wrote:
> This sounds more like an issue with file offsets being longs,
> ironically. Using longs to represent zero-based locations in a file is
> extremely unsafe. Such usages should really be restricted to short-range
> offsets from the current file position, and fpos_t used for everything
> else (which is assumably available in std.c.stdio).
1. Ironically the issue is not in file offset's signedness. You still hit the bug with ulong offset.
2. Signed offset is two times safer than unsigned as you can detect underflow bug (and, maybe, overflow). With unsigned offset you get exception if the filesystem doesn't support sparse files, so the linux will keep silence.
3. Signed offset is consistent/type-safe in the case of the seek function as it doesn't arbitrarily mutate between signed and unsigned.
4. Choosing unsigned for file offset is not dictated by safety, but by stupidity: "hey, I lose my bit!"
I AM an optimization zealot, but unsigned offsets are plain dead freaking stupid.
More information about the Digitalmars-d
mailing list