0

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])
{
    ...
}

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

4 Comments

@xtofl I also liked your terse answer, you should undelete it :-)
Thanks all for the quick response and tips. I'm creating a simulated file system that accepts unix commands for class, reason for the mkdir.
Still, use another name, like mymkdir; it is making your code confusing.
If you keep the mkdir name and link with a library calling mkdir (and a lot of C libraries might do that) you'll have big, hard to hunt, bugs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.