我有“哈希”,它是指向结构的指针。我正在尝试获取它的成员统计信息,这也是一个指针。我以为我可以这样做: hash->stats 但这似乎返回了参考统计数据结构。“->”应该只是取消引用左侧的变量吗?
struct statistics {
unsigned long long count;
...
};
struct hashtable {
GHashTable * singleton; //Single Hash Table to Store Addresses
struct statistics *stats; //Statistics Table
};
GHashTable *ghash = g_hash_table_new(NULL, NULL);
struct hashtable *hash = (struct hashtable *) malloc(sizeof(struct hashtable));
//Works but why isn't hash->stats ok?
memset(&hash->stats, 0, sizeof(struct statistics));
如果我此时尝试这个:
struct statistics *st = hash->stats;
我得到:
incompatible types when initializing type 'struct statistics *' using type 'struct
statistics'