about the code:
tp is a pointer to a certain struct which contains a table.
the table is a pointer to a pointer of a differnt struct,used as an array.
size is just the size of the table.
im sending these veriables to a function in order to initialize all the cells in the
array to NULL.
this line:
initArr(tp->table,tp->size);
sends them to this function:
void initArr(ObjectP* array,int size)
{
int i;
for (i = 0; i < size; ++i)
{
array[i]=NULL;
}
}
using the eclipse debugger i can see that the objects in the array are infact
being initialized to NULL, but when the method ends,
tp->table is NULL.
pointers gone wild?
help please.
the structs:
table:
typedef struct Table
{
size_t size;
hashFcn hash;
printFcn print;
comparisonFcn comp;
ObjectP* table;
int duplicated;
}Table;
object:
typedef struct Object
{
void *key;
ObjectP pointsTo;
}Object;
Arrays and pointers are similar but different.
An array of pointers can be represented as a number of continuous pointers in memory (with an address of where the first pointer in the array resides).
Under such a circumstance tp->table is exactly the same as tp->table[0], but the [0] is assumed (because it has the same address). In systems that are implemented in this manner, the tp->table specifies an address, and the offset from that address (to get to the element of the array) is represented as a value times the datatype size (or one pointer’s size in your case).
So your debugger might actually be printing out tp->table which is exactly equivalent to tp->table[0] depending on your compiler’s implementation.