So I'm using an old API and it has a problem I don't know how to solve.
It's something like this.
1 2 3 4 5 6 7 8 9 10
int function(int selector, void **value) {
char *names[32];
long length = getNames(names); // Returns number of elements, length is used for something else
// HERE IS THE PROBLEM, value does not get any of the names
value = (void**)names;
return 0; // Returns error code
}
You cannot change the value of a passed parameter (it is a local variable). You can only change the content (if possible of that parameter).
In your case you may pass a reference:
1 2 3 4 5 6 7 8 9 10
int function(int selector, void **&value) { // Note & in order to change value
char *names[32];
long length = getNames(names); // Returns number of elements, length is used for something else
// HERE IS THE PROBLEM, value does not get any of the names
value = (void**)names;
return 0; // Returns error code
}
One more thing i forgot to mention: You cannot assign the local variable names to the a non local variable (such as value). As soon as function(...) ends the life time of names also ends. The content of value when returning is undefined.
Generally: Do not return pointers to local variables.
So if getNames(...) returns pointers to local variable as well it would be undefined as well.