0

"How to declare an array of N pointers to functions returning pointers to
functions returning pointers to characters?

Declare it this way
char *(*(*a[N])())();

Even this seems to be correct
(char*(*fun_ptr)())(*func[n])();"

Is this syntax correct? If so is there any thing more confusing than this? Why do people invent something that is that crazy?

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Dave Sinkula
0

This might be right, then again I may have read your posting wrong

#include <stdio.h>
#include <stdlib.h>

typedef char* (*firstptr)(void);
typedef firstptr (*secondptr)(void);

int main(int argc, char**argv)
{
	secondptr myarray[10];
	exit(EXIT_SUCCESS);
}

Edited by gerard4143: n/a

1

Tried adding some data...or functions in this case

#include <stdio.h>
#include <stdlib.h>

char ch[] = "this is the string!\n";

typedef char* (*firstptr)(void);
typedef firstptr (*secondptr)(void);

char* retstr(void)
{
	return ch;
}

firstptr retfunc(void)
{
	return retstr;
}

int main(int argc, char**argv)
{
	secondptr myarray[10];
	myarray[0] = retfunc;
	fprintf(stdout, "ch->%s\n", ((firstptr)myarray[0]())());

	exit(EXIT_SUCCESS);
}

The output:
ch->this is the string!

Edited by gerard4143: n/a

Votes + Comments
Very nice, using a couple of intermediate typedefs
1

Why do people invent something that is that crazy?

When you need it, you need it. And then it's there for you.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.