Reputation: 317
I am trying to pass a typedef struct pointer to a function and the compiler is complaining with this error message: error: unknown type name ‘RootP’. Here is the code...
int main()
{
typedef struct Root
{
struct Root *child;
}*RootP;
RootP rootNode = malloc(sizeof(struct Root));
rootNode->child = NULL;
....
}
void mkdir(RootP rootNode, char param2[60], char pwd[200])
{
...
}
Upvotes: 0
Views: 1247
Reputation: 1
The struct
should be outside of main
, so move
typedef struct Root
{
struct Root *child;
}*RootP;
before the main
function. If the program is big enough, consider moving that into some header file (*.h
)
And I would avoid using the mkdir
name. It is defined in Posix and on Linux refers to the mkdir(2) system call.
I don't feel that typedef struct Root *RootP;
is pretty code: you usually want to see at a glance what C thing is a pointer. I would instead declare the struct root_st
and have typedef struct root_st Root;
(Gtk also uses that, or a very similar, coding convention). And code Root* rootnode
. But it is debatable and a matter of taste.
Upvotes: 5