2

can you define function pointer return integer pointer? answer is yes. and it should be like this---->

integer*(*function)();

and my question is , can you define function pointer return function pointer? if answer is no! teach me please. if answer is yes, tell me how please.

2
  • @alk That's why I removed the comment :P ... Commented Jun 6, 2014 at 11:50
  • 2
    Do you want C or C++? There are almost always techniques one might use in C++ that are invalid in C. Commented Jun 6, 2014 at 11:53

2 Answers 2

7

Of course you can. The easiest and most readible way is to have an intermediate typedef, something like this:

typedef int* (*pFunc)(void);

and then it's simply:

typedef pFunc (*pFuncRetFunc)(void);
Sign up to request clarification or add additional context in comments.

8 Comments

That is not valid syntax, it needs to be typedef int* (*pFunc_t)(void);.
Also, in POSIX (at least), typedefs ending in _t are reserved, so its usually best to avoid them.
or you could just use an std::function as your return type... and be C++ style.
Still the wrong syntax for defining the function-pointer type.
@Mgetz: std::function has extra overhead compared to a simple function pointer. C++ style is to avoid paying for what you don't need.
|
1
typedef int * (* (* FP)(void))(void);

This defines FP to be a type that represents a function pointer to a function returning a function pointer to a function returning a pointer to int. All function (types) involved take no arguments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.