Alexandre Silva
Alexandre Silva

Reputation: 35

struct’ declared inside parameter list with a header file

I have a simple header file with the following code:

#include < stdio.h >
#include < pthread.h >

void init(struct prodcons * b);

void put(struct prodcons * b, int data);

int get(struct prodcons * b);

void * producer(void * data);

void * consumer(void * data);

when I compile the terminal give this four warnings:

producer_consumer.h:4:18: aviso: ‘struct prodcons’ declared inside parameter list [enabled by default]
producer_consumer.h:4:18: aviso: its scope is only this definition or declaration, which is probably not what you want [enabled by default]
producer_consumer.h:6:17: aviso: ‘struct prodcons’ declared inside parameter list [enabled by default]
producer_consumer.h:8:16: aviso: ‘struct prodcons’ declared inside parameter list [enabled by default]

Upvotes: 1

Views: 6436

Answers (3)

KlaFier
KlaFier

Reputation: 159

The compiler complains about the missing declaration of "struct prodcons". You have to include a header file that actually gives a declaration of that struct, or you have to insert a forward declaration of that struct, like just writing:

struct prodcons;

Upvotes: 1

Christian Ternus
Christian Ternus

Reputation: 8492

You need to declare struct prodcons somewhere. Right now there's no declaration for it, so the compiler is inferring it.

Presumably you have a declaration for this in another file -- if it's in another header, add an #include directive for it to the top of this .h file, before all the functions that use it.

Upvotes: 1

Jonathon Reinhart
Jonathon Reinhart

Reputation: 137398

struct prodcons has not been defined anywhere. You need to define it before those prototypes, or #include a header file that defines it.

Since the parameter list is the first time the compiler has seen struct prodcons, it assumes that you are declaring it there (which makes no sense).

Upvotes: 0

Related Questions