Click to See Complete Forum and Search --> : Problem with pointer to array...
DonKrust
May 8th, 2008, 03:38 AM
Hi,
i've got the following problem:
a function is given the parameter
static void instantiate(const LV2_Feature *const* features)
where LV2_Feature is a struct:
typedef struct _LV2_Feature {
const char * URI;
void * data;
} LV2_Feature;
Now as far as i understood it, features is an array of LV2_Features. Then how do i iterate over each element of this array and test whether it's NULL or valid?
S_M_A
May 8th, 2008, 03:57 AM
You need to know either how many elements the array contain or that the last element in the array is guaranteed to be NULL. If last element always is NULL you can dofor( int i = 0; features[i]; ++i )
{
...
}
DonKrust
May 8th, 2008, 04:33 AM
It works, thank you very much!
angelorohit
May 8th, 2008, 04:35 AM
Let me clarify. Are you saying that you want to iterate over the elements of an array of type LV2_Feature until the pointer data member of an element is found to be NULL? If not, I think that the function would also need to accept the number of elements in the array.
spoon!
May 8th, 2008, 04:51 AM
static void instantiate(const LV2_Feature *const* features)
Note that you have a pointer to a const pointer to a const LV2_Feature (2 pointers, with various const's). You have to give more information about why there are so many levels of indirection and what all the things point to.
DonKrust
May 8th, 2008, 09:52 AM
You have to give more information about why there are so many levels of indirection and what all the things point to.
This is a data that is passed on from a host application to a plugin. The plugin is supposed to be able to read the data, but mustn't modify it. Why it is necessary to make it that complicated i don't know..... I didn't think it up, I just use it ;)
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.