Bug 5452 – Signed file lengths and positions

Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-01-13T16:15:00Z
Last change time
2015-01-27T10:09:17Z
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2011-01-13T16:15:53Z
In File size() returns an ulong, given by seek(): http://www.dsource.org/projects/phobos/browser/trunk/phobos/std/stdio.d?rev=2284#L585 http://www.dsource.org/projects/phobos/browser/trunk/phobos/std/stdio.d?rev=2284#L1245 It uses fseek, that seems to return a signed value: http://www.cplusplus.com/reference/clibrary/cstdio/ftell/ So isn't it better and safer if those functions of File return a long instead of an ulong? See also bug 3843 but here the values are 64 bit, so while 4 GB arrays of bytes are possible, files of just 9_223_372_036_854_775_807 bytes are not a significant limitation compared to files 18_446_744_073_709_551_615 bytes long. Currently unsigned values are quite dangerous in D, so I suggest to avoid introducing them in Phobos unless where they are necessary.
Comment #1 by andy — 2015-01-27T01:43:35Z
> isn't it better and safer The C api returns a -1 to indicate error, which the D code catches and raises an exception. Since we dont need to return an error as -1, and because files cannot have a size less than zero, it makes since to use an unsigned type. I'd say a signed type is neither better or safer. > Currently unsigned values are quite dangerous in D I don't know if that's still true, if it is you should open a new bug report with some test code.
Comment #2 by dfj1esp02 — 2015-01-27T10:09:17Z
(In reply to AndyC from comment #1) > I don't know if that's still true, if it is you should open a new bug report > with some test code. It's a semantical issue, see the linked discussion.