I have to say that your "hack" isn't very useful and it is dangerous. The local dserver pointer isn't initialized to NULL by default on automatic local variables. Essentially what you are trying to do is:
Code:
t_dserver *get_display_server( t_dserver *p )
{
// notice: Declared as static!
static t_dserver *q = NULL;
if ( !q )
q = p;
return q;
}
This is almost the same as declaring a global variable, but, instead of accessing the global variable directly, you are doing a function call and a comparison, in every access. If performance is important, this will not be good.
But, of course, this is redundant (you are passing the pointer to the function here!).
If you need to pass multiple arguments a single one I suggest you use a structure:
Code:
typedef struct {
int a;
void *p;
float x, y, z;
char *sptr;
} args_T;
void myfunc( args_T * );
args_T args = { .a = 1, .p = &xpto, .x=1.0f, .sptr = str };
myfunc(&args);
This is essentially the same as passing multiple arguments directly, but you'll need to initialize the structure only once if you want to pass the same arguments to multiple functions and your structure could be dynamically allocated if you wish:
Code:
args_T *args = malloc( sizeof *args );
*args = (args_T){ .a=1, .p=&xpto, .x=1.0f, .sptr = str; }
myfunc(args);
free(args);
And you have an advantage: unused args will be automatically initialized to 0.