gcc错误:声明说明符中的两个或多个数据类型

arg*_*oid 4 c gcc struct

gcc说我:

cc -O3 -Wall -pedantic -g -c init.c
init.c:6:1: error: two or more data types in declaration specifiers
init.c: In function 'objinit':
init.c:24:1: warning: control reaches end of non-void function
make: *** [init.o] Error 1
Run Code Online (Sandbox Code Playgroud)

代码是:

#include "beings.h"
#include "defs.h"
#include "funcs.h"
#include "obj.h"

void objinit(int type, struct object* lstrct){
     switch(type){
             case WALL:
                     lstrct->image = WALL_IMG;
                     lstrct->walk = false;
                     lstrct->price = 0;
             break;
             case WAND:
                     lstrct->image = WAND_IMG;
                     lstrct->walk = true;
                     lstrct->price = 70;
             break;
             case BOOK:
                     lstrct->image = BOOK_IMG;
                     lstrct->walk = true;
                     lstrct->price = 110;
             break;
     }
}
Run Code Online (Sandbox Code Playgroud)

我知道,WALL_IMG之类的东西是.h分隔文件,但我的代码有什么问题?

Jam*_*lis 31

我的通灵调试能力告诉我,你可能有一个结构定义obj.h,而不是用分号结束.

不正确:

struct object { /* etc. */ }
Run Code Online (Sandbox Code Playgroud)

正确:

struct object { /* etc. */ };
Run Code Online (Sandbox Code Playgroud)

为什么我这么想?错误说:

init.c:6:1: error: two or more data types in declaration specifiers
init.c: In function 'objinit':
init.c:24:1: warning: control reaches end of non-void function
Run Code Online (Sandbox Code Playgroud)

警告说编译器认为你的函数有一个非void返回类型,但你的函数显然是用void返回类型声明的.该错误表示编译器认为您的函数是使用多种类型声明的.最可能的解释是,有一个结构定义obj.h是未终止的.

  • 我喜欢你的通灵调试能力. (4认同)