Hey,
I have a function that calls itself recursively, and stores its results in a static array or structs.
The function itself works fine, however, when the function isn't called recursively, the array needs to be null'd, right now my solution to this is something like:
Code:
fooStruct **foo(char *c, int new){
. . .
static fooStruct **strct = NULL;
. . .
if(new)
strct = NULL;
And when calling the function from any other function, passing '1' as the second argument, and when calling the function recursively, passing '0'
This works, but feels and looks strange. I'm wondering if there is a more elegant solution to this problem?
Thanks in advance.