-3
我有兩個需要分配內存的指針數組,但我在轉換時遇到問題。代碼似乎是工作的罰款,但給我如何從malloc轉換爲指針數組C
warning: assignment from incompatible pointer type [enabled by default]
這些類型和mallocs代碼:
typedef struct Elem Elem;
struct Elem {
char *(*attrib)[][2]; //type from a struct
Elem *(*subelem)[]; //type from a struct
}
Elem *newNode;
newNode->attrib = (char*)malloc(sizeof(char*) * 2 * attrCounter);
newNode->subelem = (Elem*)malloc(sizeof(Elem*) * nchild);
如果他們是指針,你應該數組在你的malloc中執行(char **)和(XmElem **) – 2014-09-24 15:03:35
可能重複[我是否投出malloc?]的結果(http://stackoverflow.com/questions/605845/do-i-cast-the-結果的malloc) – 2014-09-24 15:06:44
不知道它投了一個malloc不好,我認爲這是另一回事。謝謝 – Jorgel 2014-09-24 15:09:42