Jebathon
Jebathon

Reputation: 4561

C89 - error: expected ')' before '*' token

I am getting this error within C.

error: expected ')' before '*' token

But cannot trace it.

void print_struct(struct_alias *s) //error within this line
{
...
} //end of print method

My question is when receiving this error where can the error stem back to? Is it a problem with the function, can it be an error with what is being passed in? What is the scope of the error?

Upvotes: 0

Views: 376

Answers (2)

Keith Thompson
Keith Thompson

Reputation: 263237

The compiler doesn't recognize the name struct_alias as a type name.

For that code to compile, struct_alias would have to be declared as a typedef, and that declaration would have to be visible to the compiler when it sees the definition of print_struct.

(Typedef names are tricky. In effect, they become temporarily user-defined keywords, which is why errors involving them can produce such confusing error messages.)

This is not specific to C89; it applies equally to C90 (which is exactly the same language as C89), to C99, and to C11.

Upvotes: 2

AnT stands with Russia
AnT stands with Russia

Reputation: 320431

The error means that here's no such type as struct_alias declared in this translation unit.

Upvotes: 0

Related Questions