You could initialize the memory with a sentinel value, such as zero, and then check whether array[5]
only contains that value. E.g.:
#define UNINITIALIZED 0
Node *array = calloc(53, sizeof(Node)); // don't cast malloc and friends!
Node null_node;
memset(&null_node, UNINITIALIZED, sizeof(Node));
if(memcmp(&array[5], &null_node, sizeof(Node)) == 0)
// …
Just make sure a valid Node
instance can never equal to that sentinel value.
This is more efficient than dasblinkenlight's solution, because it involves an additional indirection. However, if a safe sentinel value cannot be found, and adding an int uninitialized
(or similar) flag field to Node
is not possible, the extra pointer is necessary, unless you store the information about which elements are initialized somewhere else.