TLD
TLD

Reputation: 8135

Function pointer


In my A.h file

Node RemoveString(Node (*)(char,Node));
Node Minimum(char, Node);


In my A.c file

Node Minimum(char type, Node node) {......}
Node RemoveString(Node(*Minimum)(char, Node)) {...}


In my B.h file

void Test_Function(Node (*)(char,Node));


In my B.c file

void Test_Function(Node(*Minimum)(char, Node)) {...}


In my Main.c

Test_Function(Node(*Minimum)(char, Node));//This line has error.


Node is defined in A.h
B.h include "A.h"
Main.c include "B.h"


The compiler complains that error: expected expression before ‘Node’
Can anybody tell me why ?What i did wrong in this case?

Upvotes: 0

Views: 565

Answers (3)

Rafid
Rafid

Reputation: 20179

When you call a function, you just use the name of the function rather than the complete definition again. So this line:

Test_Function(Node(*Minimum)(char, Node));

Should be:

Test_Function(&Minimum);

Of course you should also make sure that the functions Test_Function and Minimum are defined (i.e. files included) before this statement.

Upvotes: 4

Giuseppe Ottaviano
Giuseppe Ottaviano

Reputation: 4633

The expression you are using as Test_Function argument is a type, not a function pointer. The function pointer is just the function's name:

Test_Function(Minimum);

Upvotes: 1

j_random_hacker
j_random_hacker

Reputation: 51226

You tagged this c, so I take it you're using a C compiler (not C++) -- right? In that case you need to either write struct Node in each declaration, or use a typedef.

Upvotes: 0

Related Questions