开发者

two or more data types in declaration specifiers

开发者 https://www.devze.com 2023-03-29 20:43 出处:网络
I\'ve looked around and tried a few things, nothings working at the moment. main.c:13: error: two or more data types in declaration specifiers

I've looked around and tried a few things, nothings working at the moment.

main.c:13: error: two or more data types in declaration specifiers
make[1]: *** [main.o] Error 1
make: *** [b开发者_开发问答uild] Error 2

My code is pretty much this(i've commented everything out so it's not something else + there are no other files apart from this);

main.h

struct savetype{
    bool file_exists;
}

main.c

#include "main.h"
extern struct savetype save;
int main (void){
return 0;
}

stuff.c

#include "main.h"
struct savetype save;
save.file_exists=true;


C struct declarations must end with a semicolon. Put a semicolon at the end of your struct declaration in main.h and you'll be OK.

Also, there should be a bool type available to you unless you've got some other code defining it. In C, use an int instead of a bool.

Moreover, there's no such thing as true in standard C; 0 is false and anything else is true, so you'll have to correct stuff.c as well.

Also, stuff.c shouldn't compile because it contains code (more than just declarations) outside of any function (specifically save.file_exists = true;.


This is the problem:

struct savetype{
    bool file_exists;
};
^^^^ <-------------- Here!

You forgot a semicolon in the end.


bool type doesn't exist in C. you can use a macro to use TRUE/FALSE values in a convenient way:

#define TRUE 1
#define FALSE 0

then you can use it in conditional statements like this:

if (var == TRUE){

}

if you want to use 'bool' as a keyword:

typedef int bool;

EDIT:

I didn't know that but @Bo Persson pointed out that from C99 boolean types have been introduced. To use them include the following prototype:

#include <stdbool.h>
0

精彩评论

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