D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2364 - ftell return type is long in C, that is 64-bit on x86-64
Summary: ftell return type is long in C, that is 64-bit on x86-64
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86 Windows
: P2 trivial
Assignee: No Owner
URL: http://digitalmars.com/d/2.0/phobos/s...
Keywords:
Depends on:
Blocks:
 
Reported: 2008-09-17 08:37 UTC by anonymous4
Modified: 2015-06-09 01:20 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description anonymous4 2008-09-17 08:37:33 UTC
But in D it's declared as int ftell(FILE *);
Comment 1 anonymous4 2008-10-09 07:43:27 UTC
> > So .. ptrdiff_t?
> 
> Nope, C long.  So 32 bits on Win32, Win64, and 32-bit *nix, but 64 bits 
> on 64-bit *nix.

All c types are compiler-specific, but in fact long is 64 bit on x86-64 architecture (os-independent).
Comment 2 Matti Niemenmaa 2008-10-09 12:17:41 UTC
Nope, see for instance http://en.wikipedia.org/wiki/64-bit#64-bit_data_models or try MSVC yourself: sizeof(long) == 4.
Comment 3 anonymous4 2008-10-10 02:26:19 UTC
... indeed. For some reason I thought different. Was it always like this?
Comment 4 Matti Niemenmaa 2008-10-10 04:03:28 UTC
Yes, I think it's always been like that.
Comment 5 Tomas Lindquist Olsen 2009-10-19 03:20:56 UTC
Even with the misunderstanding of C long being 32 or 64 bit, translating a C long to a D int is still wrong.
Comment 6 Brad Roberts 2009-10-19 09:20:26 UTC
Changing to resolved-fixed.  In druntime, where this stuff lives now, it's defined as a c_long:

c_long ftell(FILE* stream);
Comment 7 Andrei Alexandrescu 2009-10-20 12:10:56 UTC
I'd like to replace the antiquated fseek/ftell routines with 64-bit routines straight inside druntime. On Windows, there's _fseeki64:

http://msdn.microsoft.com/en-us/library/75yw9bf3%28VS.80%29.aspx

On Linux, there's fseeko64:

http://www.mkssoftware.com/docs/man3/fseek.3.asp

I couldn't find the appropriate OSX routine, and I wouldn't be able to test it either. I know Sean is very busy, so may I get a hand from around here?

Ideally what I'd like to do would be to take care of whatever forwarding/aliasing is needed inside druntime to make the normal fseek and ftell routines use 64-bit ulong. (Sean approved.) Please let me know if you could help, thanks!