[Numpy-discussion] f2py related question
Charles Doutriaux
doutriaux1@llnl....
Thu Sep 11 15:17:01 CDT 2008
Thanks robert,
That's exactly the information I needed.
Thanks for the link too.
C.
Robert Kern wrote:
> 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:
>
> http:// en.wikipedia.org/wiki/64-bit#64-bit_data_models
>
> 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
> uses.
>
> 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
>>>>
> 4
>
>
More information about the Numpy-discussion
mailing list