C语言 gcc 错误:声明说明符中有两个或多个数据类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4527641/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 07:24:25  来源:igfitidea点击:

gcc error: two or more data types in declaration specifiers

cgccstruct

提问by argos.void

gcc says me:

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

the code is:

代码是:

#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;
     }
}

i know, things like WALL_IMG is on a .h separated file, but whats wrong with my code?

我知道,像 WALL_IMG 这样的东西在一个 .h 分隔的文件中,但是我的代码有什么问题吗?

回答by James McNellis

My psychic debugging powers tell me that it is likely you have a struct definition in obj.hthat is not terminated with a semicolon.

我的通灵调试能力告诉我,您可能有一个结构体定义,obj.h其中没有以分号结尾。

Incorrect:

不正确:

struct object { /* etc. */ }

Correct:

正确的:

struct object { /* etc. */ };

Why do I think this? The errors say:

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

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

The warning says the compiler thinks your function has a non-void return type, yet your function is clearly declared with a voidreturn type. The error says that the compiler thinks your function is declared with multiple types. The most likely explanation is that there is a struct definition in obj.hthat is unterminated.

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