03-30-2010 12:00 PM - edited 03-30-2010 12:03 PM
Hi,
in the past life was apparently simpler with some of the NI functions... In most functions, integer values were declared as int. Now, with the possibility to have both 32 bit and 64 bit integers (CVI2009), many NI function declarations changed. It seems to me, that this did not always happen in a consistent manner. Example:
PlotXY requires for the number of points to plot a value of type size_t.
If I want to use the array functions to operate on the arrays I am going to plot, e.g. using Clear1D, the number of elements has to be specified as ssize_t.
What is the user expected to do if he/she wants to define the size of the array of x and y data, which are both initialized and plotted ?
Should the integer number of points be declared as size_t or as ssize_t to allow for both 32 bit and 64 bit compilation?
Thanks!
Solved! Go to Solution.
03-31-2010 11:51 AM
The general rule used for these 64-bit-related changes was to change to size_t the parameters of some functions (usually array length or array index parameters) that already support, or might one day support, values greater than LONG_MAX. That change had to take place now, when there were no 64-bit CVI programs in existance, rather than at some point in the future where compile-time compatibility with existing 64-bit programs will be a concern.
Some libraries (like the Analysis library) often take special negative values (-1) through these parameters, so they couldn't be changed to size_t. Therefore, they were changed to ssize_t instead. This means that those buffers can never exceed 1<< 63 (as opposed to 1 << 64), but that's not a major limitation.
Note that for input parameters (such as those in Clear1D and PlotXY) you can continue using int variables, and you'll never have any compilation issues, whether you're building 32- or 64-bit programs. You'd only have to change to size_t or ssize_t if you ever want to use large arrays.
If they're output parameters, I recommend that you go ahead and change them to size_t or ssize_t now so that you don't have compilation errors if you ever want to build 64-bit targets later.
As for cases where you need to have a single variable that you use with both a ssize_t and a size_t function (like Clear1D and PlotXY), it doesn't matter much which of those two you use. Technically, it depends on whether you might eventually need to store negative values, or values greater than 1>>>63. But I don't think the compiler will complain when you pass a size_t variable to a ssize_t parameter, or vice-versa. And if it does complain, you can always use a cast.
Luis
Luis
03-31-2010 12:24 PM
Thanks, Luis, for the explanation! I agree that both 63 and 64 bit should be sufficient, I was just wondering about the signed/unsigned mismatch.
Wolfgang