[Numpy-discussion] Mapping of dtype to C types

Nathaniel Smith njs at pobox.com
Sun May 8 17:57:49 EDT 2011


On Sun, May 8, 2011 at 2:45 PM, Keith Goodman <kwgoodman at gmail.com> wrote:
> I'm writing a function that accepts four possible dtypes: int32,
> int64, float32, float64. The function will call a C extension (wrapped
> in Cython). What are the equivalent C types? int, long, float, double,
> respectively? Will that work on all systems?

I think you're fine on float and double, but on many systems 'long' is 32 bits.

#include <stdint.h>
int32_t this_is_32_bits;
int64_t this_is_64_bits;

(There may still be compilers out there that don't come with stdint.h
by default, but if you need to support them then you'll be able to
find appropriate autoconf goo to create it, since it's a standard
interface.)

-- Nathaniel



More information about the NumPy-Discussion mailing list