Reputation: 53
I want to write a function prototype for a function, whose argument is a pointer to a struct.
int mult(struct Numbers *n)
However, the struct Numbers, which is defined as
struct Numbers {
int a;
int b;
int c;
};
is not defined yet. How should I write a suitable prototype for mult?
Upvotes: 5
Views: 12601
Reputation: 133557
You must forward the declaration of the structure to tell the compiler that a struct with that name will be defined:
struct Numbers;
int mult(struct Numbers *n) {
}
struct Numbers {
int a;
int b;
int c;
};
Mind that the compiler is not able to determine the size in memory of the structure so you can't pass it by value.
Upvotes: 4
Reputation: 145829
Just declare struct Numbers
as an incomplete type before your function declaration:
struct Numbers;
int mult(struct Numbers *n);
Upvotes: 5