gpt4 book ai didi

c - 为什么我会收到此错误 : "data definition has no type or storage class"?

转载 作者:太空狗 更新时间:2023-10-29 16:58:01 24 4
gpt4 key购买 nike

#include <stdio.h>
#include <stdlib.h>

struct NODE {
char* name;
int val;
struct NODE* next;
};
typedef struct NODE Node;

Node *head, *tail;
head = (Node*) malloc( sizeof( Node ) ); //line 21

我这样编译:

cc -g -c -o file.tab.o file.tab.c

我收到此错误消息:

file.y:21:1 warning: data definition has no type or storage class [enabled by default]

最佳答案

看起来像线

head = (Node*) malloc( sizeof( Node ) ); //line 21

main() 函数之外。你不能那样做,因为你不能在函数外执行代码。您在全局范围内唯一可以做的就是声明变量。只需将它移到 main() 或任何其他函数中,问题就会消失。

(PS:看看 this question 为什么你不应该类型转换 malloc)

关于c - 为什么我会收到此错误 : "data definition has no type or storage class"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18906190/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com