[Numpy-discussion] int16 or int32 for C int ?

Nicolas Pernetty nicopernetty at yahoo.fr
Mon Jun 27 16:48:15 CDT 2005


On Mon, 27 Jun 2005 06:16:33 -0400, Todd Miller <jmiller at stsci.edu>
wrote :

> > > > I would like to create a numarray array from a C buffer of 'int'
> > > > but I don't quite know how to handle different 'int'
> > > > representation (16 or 32 bits).
> > > 
> > > On the platforms we test on at least,  int == Int32.  This is even
> > > true for the 64-bit platforms I've seen.
> > > 
> > > > For instante should I use :
> > > > 
> > > > int a[10][20];
> > > > x = NA_NewArray(a, tInt16, 2, 10, 20);
> > > > 
> > > > or :
> > > > int a[10][20];
> > > > x = NA_NewArray(a, tInt32, 2, 10, 20);
> > > > 
> > > > Should I use some macro to determine size of int ?
> > > 
> > > You can do that with: sizeof(int)
> > > 
> > 
> > Ok so If I want to make a really multiplatforms program, I should
> > type :
> > 
> > int a[10][20];
> > if (sizeof(**a)==4)
> >     x = NA_NewArray(a, tInt32, 2, 10, 20);
> > else
> >     x = NA_NewArray(a, tInt16, 2, 10, 20);
> > 
> > This is the recommended way ?
> 
> I think this would be better:
> 
> Int32 a[10][20];
> 
> x = NA_NewArray(a, tInt32, 2, 10, 20);
> 
> Or,  just do:
> 
> x = NA_NewArray(NULL, tInt32, 2, 10, 20)
> 
> and numarray will allocate the array storage which is then pointed to
> by x->data.
> 

Ok but in my particular case I can't : I have to deal with legacy code
which use 'int' so I'm stuck with the sizeof trick...

Thanks anyway !




More information about the Numpy-discussion mailing list