Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a structure is initialized?

I have a table that I'm implementing with data structures. An important block of my code looks like this(h is a data structure, table is a table that stores other structures):

(h->table[hash(key, h->size)]

While my code is running, some table[i]'s will be initialized, and some aren't. Whenever I test my code on a table[i] that hasn't been initialized yet, I get a valgrind error which basically says I can't work with an uninitialized array.

My question is, how would I check to see if a certain h->table[i] is initialized or not?

like image 750
user1710702 Avatar asked Apr 19 '13 06:04

user1710702


1 Answers

You can't. To fix the problem, always initialize the struct before using it (even if all the initialization does is set the struct to a known "blank"/"not populated" state).

like image 155
NPE Avatar answered Oct 12 '22 07:10

NPE