pea
developer
Hi all,
I was getting back into c today and came across a bug which I think affects every 'free' routine I have written for the GP so far...
I develop using a psuedo OO format, much like openGL does it. I have structs (objects) and I have functions which create and free those structs (constructors and destructors) and I have functions which act on those structs as the first input param (methods).
If I pass in a 'pointer to my struct' (e.g. tGP_struct *struct), the 'struct' variable inside the function now contains the address of the struct, right? If I now set this to NULL, this does not affect the struct outside the function, does it?
To make this work effectively, I would have to pass in the reference to the pointer? (tGP_struct **struct) ?
I was getting back into c today and came across a bug which I think affects every 'free' routine I have written for the GP so far...
I develop using a psuedo OO format, much like openGL does it. I have structs (objects) and I have functions which create and free those structs (constructors and destructors) and I have functions which act on those structs as the first input param (methods).
If I pass in a 'pointer to my struct' (e.g. tGP_struct *struct), the 'struct' variable inside the function now contains the address of the struct, right? If I now set this to NULL, this does not affect the struct outside the function, does it?
Code:
void gp_structFree( tGP_struct *struct ){
free(struct);
struct=NULL;
}
tGP_struct *struct;
struct = gp_structCreate();
gp_structFree( struct );
if (struct){ // This could theoretically still be true? }
To make this work effectively, I would have to pass in the reference to the pointer? (tGP_struct **struct) ?