![](https://secure.gravatar.com/avatar/40815e9f08d15c3b5f6db22ac908f424.jpg?s=120&d=mm&r=g)
Hello, 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). 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 ? Thanks in advance for any help,
![](https://secure.gravatar.com/avatar/40815e9f08d15c3b5f6db22ac908f424.jpg?s=120&d=mm&r=g)
On Sun, 26 Jun 2005 21:28:25 -0400, Todd Miller <jmiller@stsci.edu> wrote :
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 ? Thanks !
![](https://secure.gravatar.com/avatar/3b77bd3bdc83a29248c8e44dbfddb28e.jpg?s=120&d=mm&r=g)
Nicolas Pernetty <nicopernetty@yahoo.fr> writes:
On the platforms we test on at least, int == Int32. This is even true for the 64-bit platforms I've seen.
Didn't some Crays have 64bit ints? They definitely had 64bit float and 128bit double.
Maybe you should right away include a test for 8byte as well. Greetings, Jochen -- Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de Liberté, Égalité, Fraternité GnuPG key: CC1B0B4D (Part 3 you find in my messages before fall 2003.)
![](https://secure.gravatar.com/avatar/40815e9f08d15c3b5f6db22ac908f424.jpg?s=120&d=mm&r=g)
On Mon, 27 Jun 2005 11:27:40 +0200, Jochen Küpper <jochen@fhi-berlin.mpg.de> wrote :
On this page you have some exotic 'int' : http://www.doc.ic.ac.uk/lab/secondyear/cstyle/node20.html The problem was no as simple as it seems to be. I'll go with the sizeof trick and some error message if I'm dealing with an exotic 'int'...
![](https://secure.gravatar.com/avatar/faf9400121dca9940496a7473b1d8179.jpg?s=120&d=mm&r=g)
On Mon, 2005-06-27 at 09:36 +0200, Nicolas Pernetty wrote:
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. Regards, Todd
![](https://secure.gravatar.com/avatar/38d5ac232150013cbf1a4639538204c0.jpg?s=120&d=mm&r=g)
On 6/26/05, Todd Miller <jmiller@stsci.edu> wrote:
Hi, The June 2005 C/C++ Users Journal (vol 23 no 5 http://www.cuj.com) had a couple of articles on porting to 64 bit computing. One was by Rodney Mach who gave this information: the 32-bit environment is a "ILP32 model because the C data-type model has 32-bit integers, long and pointers". "All modern 64-bit UNIX-like platforms use the LP64 data model" where longs and pointers are 64 bit but ints are 32-bit. He also looked at some of the porting problems. Bruce
![](https://secure.gravatar.com/avatar/5c7407de6b47afcd3b3e2164ff5bcd45.jpg?s=120&d=mm&r=g)
On Monday 27 June 2005 02:33, Nicolas Pernetty wrote:
As Todd said, int is 32 bits in most compilers. If you want to use 16-bit ints, use the short int declaration: short int a[10][20]; x = NA_NewArray(a, tInt16, 2, 10, 20); which should work on most modern platforms. -- Francesc
![](https://secure.gravatar.com/avatar/35eca8411b3624637c55a64c4ce1f776.jpg?s=120&d=mm&r=g)
Nicolas Pernetty wrote:
If you compile this on a machine with 64-bit ints, it is better if it fails here than proceed as if working with 2-byte ints. If I am sure I'll never run into that case, I'd do it as above (with the abort()). A good C compiler can realize the test is constant and simply generate one arm of the conditions anyway. If I think it might possibly be used on a 64-bit int system, I'd go ahead and worry about what exception to raise (probably PyTypeError, but ...). --Scott David Daniels Scott.Daniels@Acm.Org
![](https://secure.gravatar.com/avatar/40815e9f08d15c3b5f6db22ac908f424.jpg?s=120&d=mm&r=g)
On Mon, 27 Jun 2005 10:40:13 -0700, Scott David Daniels <Scott.Daniels@Acm.Org> wrote :
Damn ! I was so sure that 'int' could only be 16 or 32 bits then I found this page : http://www.doc.ic.ac.uk/lab/secondyear/cstyle/node20.html Well thank you for your suggestion, I'll adopt it ! Regards,
![](https://secure.gravatar.com/avatar/40815e9f08d15c3b5f6db22ac908f424.jpg?s=120&d=mm&r=g)
On Sun, 26 Jun 2005 21:28:25 -0400, Todd Miller <jmiller@stsci.edu> wrote :
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 ? Thanks !
![](https://secure.gravatar.com/avatar/3b77bd3bdc83a29248c8e44dbfddb28e.jpg?s=120&d=mm&r=g)
Nicolas Pernetty <nicopernetty@yahoo.fr> writes:
On the platforms we test on at least, int == Int32. This is even true for the 64-bit platforms I've seen.
Didn't some Crays have 64bit ints? They definitely had 64bit float and 128bit double.
Maybe you should right away include a test for 8byte as well. Greetings, Jochen -- Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de Liberté, Égalité, Fraternité GnuPG key: CC1B0B4D (Part 3 you find in my messages before fall 2003.)
![](https://secure.gravatar.com/avatar/40815e9f08d15c3b5f6db22ac908f424.jpg?s=120&d=mm&r=g)
On Mon, 27 Jun 2005 11:27:40 +0200, Jochen Küpper <jochen@fhi-berlin.mpg.de> wrote :
On this page you have some exotic 'int' : http://www.doc.ic.ac.uk/lab/secondyear/cstyle/node20.html The problem was no as simple as it seems to be. I'll go with the sizeof trick and some error message if I'm dealing with an exotic 'int'...
![](https://secure.gravatar.com/avatar/faf9400121dca9940496a7473b1d8179.jpg?s=120&d=mm&r=g)
On Mon, 2005-06-27 at 09:36 +0200, Nicolas Pernetty wrote:
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. Regards, Todd
![](https://secure.gravatar.com/avatar/38d5ac232150013cbf1a4639538204c0.jpg?s=120&d=mm&r=g)
On 6/26/05, Todd Miller <jmiller@stsci.edu> wrote:
Hi, The June 2005 C/C++ Users Journal (vol 23 no 5 http://www.cuj.com) had a couple of articles on porting to 64 bit computing. One was by Rodney Mach who gave this information: the 32-bit environment is a "ILP32 model because the C data-type model has 32-bit integers, long and pointers". "All modern 64-bit UNIX-like platforms use the LP64 data model" where longs and pointers are 64 bit but ints are 32-bit. He also looked at some of the porting problems. Bruce
![](https://secure.gravatar.com/avatar/5c7407de6b47afcd3b3e2164ff5bcd45.jpg?s=120&d=mm&r=g)
On Monday 27 June 2005 02:33, Nicolas Pernetty wrote:
As Todd said, int is 32 bits in most compilers. If you want to use 16-bit ints, use the short int declaration: short int a[10][20]; x = NA_NewArray(a, tInt16, 2, 10, 20); which should work on most modern platforms. -- Francesc
![](https://secure.gravatar.com/avatar/35eca8411b3624637c55a64c4ce1f776.jpg?s=120&d=mm&r=g)
Nicolas Pernetty wrote:
If you compile this on a machine with 64-bit ints, it is better if it fails here than proceed as if working with 2-byte ints. If I am sure I'll never run into that case, I'd do it as above (with the abort()). A good C compiler can realize the test is constant and simply generate one arm of the conditions anyway. If I think it might possibly be used on a 64-bit int system, I'd go ahead and worry about what exception to raise (probably PyTypeError, but ...). --Scott David Daniels Scott.Daniels@Acm.Org
![](https://secure.gravatar.com/avatar/40815e9f08d15c3b5f6db22ac908f424.jpg?s=120&d=mm&r=g)
On Mon, 27 Jun 2005 10:40:13 -0700, Scott David Daniels <Scott.Daniels@Acm.Org> wrote :
Damn ! I was so sure that 'int' could only be 16 or 32 bits then I found this page : http://www.doc.ic.ac.uk/lab/secondyear/cstyle/node20.html Well thank you for your suggestion, I'll adopt it ! Regards,
participants (6)
-
Bruce Southey
-
Francesc Altet
-
Jochen Küpper
-
Nicolas Pernetty
-
Scott David Daniels
-
Todd Miller