【问题标题】:warning: type defaults to 'int' in declaration of 'root' [-Wimplicit-int]|警告:“root”声明中的类型默认为“int”[-Wimplicit-int]|
【发布时间】:2020-10-19 02:54:11
【问题描述】:

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

struct test{
int data;
struct test *link;
};
struct test *root;
root=(struct test*)malloc(sizeof(struct test));

我得到错误: 警告:数据定义没有类型或存储类| 警告:“root”声明中的类型默认为“int”[-Wimplicit-int]|

【问题讨论】:

  • 那是您完整的实际代码吗?您不能在全局范围内调用函数。需要在函数中调用它们。

标签: c pointers


【解决方案1】:

您不能在 C 中从全局范围调用代码,请使用 main()

#include <stdio.h>
#include <stdlib.h>
struct test{
   int data;
   struct test *link;
};

int main(){
   struct test *root;
   root=(struct test*)malloc(sizeof(struct test));

   //  Then write some meaningful code here
   //  remember to test if root is null and exit if malloc failed

   //  and finally free your allocated memory  
   free(root);
                                                                                                                                                         
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-04
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 2019-10-13
    • 2011-06-12
    • 1970-01-01
    相关资源
    最近更新 更多