0

The function interface being used requires a single generic void pointer argument:

void* function(void* p_void) { ... }

The argument I need to pass happens to be an array of objects. Let's go back to something simpler; for a normal datatype, it's possible to write:

void* function(void* p_void) {
    type* p_object = static_cast<type*>(p_void);
}

Is replacing this type of syntax for arrays possible? If it is, I'm not sure how that works -- how would the function know how long the array is?

Is there a reference that shows how to do this? Something like Range[]* p_array = static_cast<[Range]*>(p_void) obviously doesn't work in C.

11
  • You need to pass also the number of elements in the array. Commented Feb 10, 2021 at 19:25
  • And then do some pointer arithmetic or array indexing on each element. As an aside, C and C++ are two different languages. Commented Feb 10, 2021 at 19:26
  • 2
    Are you using C or C++? In C++, you'd probably use a template. Commented Feb 10, 2021 at 19:27
  • 1
    The implications should be no different than for a normal array. Just make sure you don't access the vector in multiple threads. Commented Feb 10, 2021 at 19:34
  • 1
    Is there any reason you're not using sdt::thread so you can avoid all of this void* trouble? Commented Feb 10, 2021 at 19:35

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.