开发者

gcc error: two or more data types in declaration specifiers

gcc says me:

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?


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

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 void return 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.h that is unterminated.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜