jgabb
jgabb

Reputation: 554

Passing global pointer to function

I declare a global struct Word *root = NULL; which I populate by using some pthread calls(created a BST) and when I go to print out an inorder traversal function by calling inorder(Word *root), it gives me an error saying "unexpected type name 'Word': expected expression". I don't understand what am I doing wrong.

void ordered(Word *root); // declaring function
//code//
Word *root = NULL; // declare global pointer to root

/*Main*/
//code that does some work and eventually creates a BST with root

ordered(Word *root); //call to my function

Upvotes: 2

Views: 668

Answers (1)

barak manos
barak manos

Reputation: 30136

Follow these rules:

  • You must specify the variable type when you declare the function
  • You may specify the variable name when you declare the function
  • You must not specify the variable type when you call the function

In your example, the variable type is Word* and the variable name is root.

So change this:

ordered(Word *root); //call to my function

To this:

ordered(root); //call to my function

Upvotes: 4

Related Questions