出於某種原因,如果我試圖得到mystruct
實際大小我不斷收到尺寸1.大小在C結構的等於1
我知道mystruct
持有的數據,因爲我可以轉儲出來,並一切都在mystruct
。
獲得大小1的原因是什麼? 感謝
// fragments of my code
struct mystruct {
char *raw;
int count;
};
struct counter {
int total; // = 30
}
static struct mystruct **proc()
{
int i = 0;
gchar *key,*val;
struct mystruct **a_struct;
struct counter c;
a_struct = (struct mystruct **)malloc(sizeof(struct mystruct *)*c.total);
while (table (&iter, (gpointer) &key, (gpointer) &val)) {
a_struct[i] = (struct mystruct *)malloc(sizeof(struct mystruct));
a_struct[i]->raw = (char*)key;
a_struct[i++]->count = (int)val;
}
size_t l = sizeof(a_struct)/sizeof(struct mystruct*);
printf("%d",l); // outputs 1
}
此外,使用%zu代替size_t的%d格式說明符。 – 2010-03-10 19:34:57
謝謝,解決了這個問題! – Josh 2010-03-10 19:35:30