struct abc
{
//some members
}arrayOf[10];
struct def
{
//some data memebers
}obj;
typedef void (*abc) (obj)
I am not sure what does the statement typedef void (*abc) (obj)
implies. Please consider that I am new to this.
struct abc
{
//some members
}arrayOf[10];
struct def
{
//some data memebers
}obj;
typedef void (*abc) (obj)
I am not sure what does the statement typedef void (*abc) (obj)
implies. Please consider that I am new to this.
Even ignoring the missing semicolon, it doesn't mean anything; it's an error.
If obj
were a type name, it would define abc
as an alias for the type void (*)(obj)
, i.e., as a pointer to a function taking a single argument of type obj
and returning void
.
But since obj
is an object name, not a type name, that's not actually what it means.
When I compile it with gcc, I get a warning:
warning: parameter names (without types) in function declaration
When I compile with -pedantic-errors
, the warning becomes a fatal error.
An old-style (non-prototype) function definition can legally specify names, but not types, for arguments:
void old_style_func(obj)
/* obj is implicitly of type int */
{
}
But that form is not valid for a function declaration. In a declaration, a single identifier between the parentheses has to be a type name, not the name of a parameter -- which makes the declaration a prototype.
gcc's error message implies that it's trying to interpret it as if it were the beginning of an old-style definition, and then deciding that it's invalid because it's just a declaration.
The bottom line is that you should pay close attention to compiler warnings.
We could speculate about what was intended. Perhaps obj
was meant to be a type name, and this:
struct def
{
//some data memebers
}obj;
was supposed to be:
typedef struct def
{
// some data members
} obj;
Or perhaps a type name was accidentally omitted, and the last line should have been:
typedef void (*abc) (struct def obj);
though in that case the name obj
is being used twice for different purposes (legal, but confusing). But without more context, it's impossible to be sure how to "fix" it.
Where did this code come from? Are you sure you've shown us the exact code? What happened when you tried to compile it?
it defines the type abc
as a pointer to a function that accepts one argument of type int
called obj
and returns nothing (void
).
It introduces a new name abc
for the type of a pointer to a function that takes an obj
and returns void
. The type of a pointer-to-function is always specified in this roundabout way in a declaration:
return-type
(*
name-being-declared)(
parameter-list)
Incidentally, the *
in the declaration is probably unnecessary. Function types always magically turn into pointer-to-function types when you need them (like how an array type magically turns into a pointer-to-element type), and you can use a function type directly (instead of a pointer-to-function type) to declare a new function.
As others have pointed out, the context you give doesn't have a type named obj
, only an object named obj
. If this code compiles, there must be another type named obj
defined somewhere else, in code you haven't given.