Gcc error: two or more data types in ad specs

gcc tells 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 

code:

 #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 are in the .h separated file, but what is wrong with my code?

+4
source share
1 answer

My psychic debugging abilities tell me that you probably have a structure definition in obj.h that does not end with a semicolon.

Wrong:

 struct object { /* etc. */ } 

Right:

 struct object { /* etc. */ }; 

Why do I think so? Mistakes 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 that the compiler believes that your function has a non-military return type, but your function is clearly declared with a void return type. The error says that the compiler considers that your function is declared by several types. The most likely explanation is that obj.h has a structure definition that is not destroyed.

+26
source

Source: https://habr.com/ru/post/1333305/


All Articles