Reputation: 21
I have the following function prototype:
char *(*scan)(char *, char *, char *, char *, int , int);
scanleft() is a function and has the type of static char *.
When I try to compile, I found that there is a pointer type mismatch between scan and scanleft.
if ((subtype & 1) ^ zero) scan = scanleft; else scan = scanright;
What does the prototype of scan() mean?
Upvotes: 0
Views: 71
Reputation: 881373
char *(*scan)(char *, char *, char *, char *, int , int);
This defines a function pointer scan
, which points to a function that accepts four char *
and two int
parameters, and returns a char *
.
That means you can do things like:
char *scanLeft(char *p1, char *p2, char *p3, char *p4, int p5, int p6) {
// do something
}
char *scanRight(char *p1, char *p2, char *p3, char *p4, int p5, int p6) {
// do something else
}
:
scan = scanLeft; char *xyzzy = scan("a", "b", "c", "d", 271828, 314159);
scan = scanRight; char *plugh = scan("a", "b", "c", "d", 271828, 314159);
and the two calls via the scan
function pointer will go to different functions.
Upvotes: 0
Reputation: 85767
scan
is not a function; it has no prototype.
scan
is a pointer to a function (taking a pointer to char
, pointer to char
, pointer to char
, pointer to char
, int
, and int
) and returning a pointer to char
.
According to your description, scanleft
isn't a function either; it's a pointer to char
.
The only prototype in your question is this:
char *, char *, char *, char *, int , int
... which doesn't look particularly confusing to me. It's 6 straightforward parameters.
Upvotes: 2