I want to pass an array of long long to an objective c function. I would like the array to be passed as a pointer, if possible, so that copying is not done. I wrote this code:
+ (int) getIndexOfLongLongValue: (long long) value inArray: (long long []) array size: (int) count
{
for (int i =0; i < count; i++)
{
if (array[i] == value)
return i + 1;
}
return 0;
}
to which I pass
long long varname[count];
as the second argument. I am wondering if I can pass this array as a pointer or if this method is fine. I don’t need pointers to long longs but pointers to the array.
It is being passed in as a pointer (language pedantry notwithstanding); nothing’s getting copied.
type[]is, for the most part, the same thing astype*.To confirm this, check out
sizeof(array)in the method. You’ll see it’s the same size assizeof(void*).If you really want a pointer to the array, i.e. a pointer to a pointer to the long longs, you’ll need to use something like
type**; but the only reason to want to do this is if you want to modify the underlying array pointer from the method, which is hardly ever the case.