[Numpy-discussion] f2py related question

Robert Kern robert.kern@gmail....
Thu Sep 11 14:54:37 CDT 2008

On Thu, Sep 11, 2008 at 14:12, Charles Doutriaux <doutriaux1@llnl.gov> wrote:
> Hello,
> I have a quick question that I'm hoping f2py developpers will be able to
> quickly answer
> I have some C code, input type can be either int or long
> I'm trying to write some fortran interface to it
> my understanding is that
> integer in fortran corresponds to int
> integer(kind=2) matches short
> but what would match long ?

Unfortunately, it depends on your system. A C long is defined to be at
least as large as an int. Incidentally, an int is defined to be at
least as long as a short and a short is defined to be at least as long
as a char. So you *could* have char == short == int == long == 1 byte,
but no such system exists (I hope!).

On pretty much all 32-bit systems I am aware of, int == long == 4
bytes. On 64-bit systems, things get a little more fragmented. Most
UNIX-type 64-bit systems, long == 8 bytes. On Win64, however, long ==
4 bytes. This section of the Wikipedia article on 64-bit computing
gives more detail:


Furthermore, it's not just the OS that determines the data model, but
also the options that are given to your compiler when building your
program *and also all of the libraries and system libraries* that it

Fortunately, there's an easy way for you to tell: just ask numpy.
Python ints are C longs, and the default numpy int dtype matches
Python ints. On my 32-bit system:

>>> import numpy
>>> numpy.dtype(int).itemsize

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
 -- Umberto Eco

More information about the Numpy-discussion mailing list