Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcc error: two or more data types in declaration specifiers

Tags:

c

gcc

struct

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?

like image 737
argos.void Avatar asked Nov 27 '22 02:11

argos.void


1 Answers

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.

like image 191
James McNellis Avatar answered Jan 21 '23 11:01

James McNellis