我想声明的虚拟head*
为全局变量,但IDE是给这个错误:初始值设定元素不是常数
initializer element is not constant
我怎么能解决呢?
typedef struct MyNode{
struct MyNode *next;
int value;
}Node;
//Declare a global variable
Node *head = malloc(sizeof(Node));
head->next = NULL;
取而代之的是让虚拟节点成为'Node head; head.next = NULL;'然后使用'&head'代码以前使用'head'的地方。 – chux
IDE不会发出这种错误。这是什么编译器? – usr2564301
请说明你的约束和要求是什么。显而易见的事情就是将'head'变量声明为全局变量,然后在函数中进行初始化。 – kaylum