CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2008
    Posts
    3

    Problem with pointer to array...

    Hi,
    i've got the following problem:

    a function is given the parameter

    Code:
     static void instantiate(const LV2_Feature *const* features)
    where LV2_Feature is a struct:

    Code:
     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?

  2. #2
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Problem with pointer to array...

    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 do
    Code:
    for( int i = 0; features[i]; ++i )
    {
      ...
    }

  3. #3
    Join Date
    May 2008
    Posts
    3

    Re: Problem with pointer to array...

    It works, thank you very much!

  4. #4
    Join Date
    Oct 2006
    Location
    Singapore
    Posts
    346

    Re: Problem with pointer to array...

    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.
    Believe in your Dreams, Work for what you Believe in.
    My thoughts? Angelo's Stuff
    Some fun things I've done: RayWatch, QuickFeed, ACSVParser

    @ngelo

  5. #5
    Join Date
    Dec 2006
    Posts
    166

    Re: Problem with pointer to array...

    Quote Originally Posted by DonKrust
    Code:
     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.

  6. #6
    Join Date
    May 2008
    Posts
    3

    Re: Problem with pointer to array...

    Quote Originally Posted by spoon!
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured