"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?

Recommended Answers

All 3 Replies

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);
}

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!

commented: Very nice, using a couple of intermediate typedefs +19

Why do people invent something that is that crazy?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.