On 30/11/15 03:35, Chris Barker - NOAA Federal wrote:
> Talk to the compiler / OS authors -- if you use a C long, you'll get
> that on *nix ( with gcc), but you won't get it on Windows with MSVC.
A C long is by definition the fastest integer type of at least 32 bits.
The AMD64 system uses natively a 64 bit pointer with a 32 bit offset.
The fastest and native integer is 32 bits.
On Windows 64 MSVC or MinGW-w64 a C long is 32 bits. Thus, the C
standard is implemented correctly because this is the fastest integer
with at least 32 bits.
64 bit long is breaking the C standard on AMD64 because it is not the
fastest integer type of at least 32 bits. C compilers on OSX, Linux and
Cygwin are not following the C standard.
Fortran compilers do it correctly on all platforms, however, as they all
default to 32 bit integer (integer*4) unless you specify otherwise.
Fortran requires that an integer without kind number should default to
the fastest on the platform, which is 32 bits on AMD64.
If you want an integer the size of a void* you should use intptr_t. If
you want an integer that can hold the maximum segment size you should
use size_t. If you want the fastest offset to a pointer you should use
int (at least 16 bits), long (at least 32 bits) or long long (at least
64 bits). Normally you want to index with long.
Do not assume that a long is 64 bits or that an int is 32 bits. Both of
these assumptions are wrong and very common programming mistakes.
Sturla