I have structs like this:
struct Child
{
int foo;
char bar[42];
};
struct Parent
{
long foobar;
struct Child ** children;
size_t num_children;
}
I have defined an API like this:
struct Parent * ParentAlloc() { struct Parent* ptr = (struct Parent*)calloc(1, sizeof(struct Parent));
ptr->children = (struct Child**)calloc(SOME_NUMBER, sizeof(struct Child*));
return ptr;
}
Now, if I want to delete a (previously allocated) child - assuming index is not out of bounds:
void FreeChild(struct Parent* parent, const size_t index)
{
free(parent->children[index]);
//now I want to mark the address pointed to in the array of pointers as null, to mark it as available
//I dont think I can do this (next line), since I have freed the pointer (its now "dangling")
parent->children[index] = 0; // this is not right. How do I set this 'freed' address to null ?
}