Defining a function which returns a function pointer which also returns a function pointer without typedefsHow do function pointers in C work?Understanding typedefs for function pointers in CTypedef function pointer?Returning function pointer typetypedef function pointers and extern keywordError with function pointer returning a (void *)Passing capturing lambda as function pointerPass typedefed function pointerReturn a function pointer without a typedef

Will replacing a fake visa with a different fake visa cause me problems when applying for a legal study permit?

Georgian capital letter “Ⴒ” (“tar”) in pdfLaTeX

Are the definite and indefinite integrals actually two different things? Where is the flaw in my understanding?

Why do sellers care about down payments?

How does Vivi differ from other Black Mages?

Is there a star over my head?

Evidence that matrix multiplication cannot be done in O(n^2 poly(log(n))) time

Kerning feedback on logo

Random point on a sphere

Can a new chain significantly improve the riding experience? If yes - what else can?

Are Democrats more likely to believe Astrology is a science?

Why the word "rain" is considered a verb if it is not possible to conjugate it?

Exact Brexit date and consequences

How is the Team Scooby Doo funded?

Why should I always enable compiler warnings?

Gas pipes - why does gas burn "outwards?"

If you have multiple situational racial save bonuses and are in a situation where they all apply do they stack?

Might have gotten a coworker sick, should I address this?

Do ibuprofen or paracetamol cause hearing loss?

extract lines from bottom until regex match

Does the amount of +1/+1 from *prowess* remain on a creature, even when a creature gets flipped face-down by Ixidron?

Why does F + F' = 1?

Seized engine due to being run without oil

What does "synoptic" mean in avionics?



Defining a function which returns a function pointer which also returns a function pointer without typedefs


How do function pointers in C work?Understanding typedefs for function pointers in CTypedef function pointer?Returning function pointer typetypedef function pointers and extern keywordError with function pointer returning a (void *)Passing capturing lambda as function pointerPass typedefed function pointerReturn a function pointer without a typedef






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








8















I am trying to really understand function pointers without using typedef but cannot seem to get this. I do not understand what signature is needed to convey that I return a pointer to a pointer to a function.



#include <stdio.h>

void odd() printf("odd!n");
void even() printf("even!n");

void (*get_pfn(int i))()

return i % 2 == 0 ? &even : &odd;


__SIGNATURE__

return &get_pfn;


int main()

get_pfn_pfn()(1)();
get_pfn_pfn()(2)();
return 0;



To make this work, what does __SIGNATURE__ have to be?










share|improve this question





















  • 5





    Good question - now don't ever do this again. :)

    – Michael Dorgan
    10 hours ago






  • 5





    use cdecl

    – Antti Haapala
    9 hours ago


















8















I am trying to really understand function pointers without using typedef but cannot seem to get this. I do not understand what signature is needed to convey that I return a pointer to a pointer to a function.



#include <stdio.h>

void odd() printf("odd!n");
void even() printf("even!n");

void (*get_pfn(int i))()

return i % 2 == 0 ? &even : &odd;


__SIGNATURE__

return &get_pfn;


int main()

get_pfn_pfn()(1)();
get_pfn_pfn()(2)();
return 0;



To make this work, what does __SIGNATURE__ have to be?










share|improve this question





















  • 5





    Good question - now don't ever do this again. :)

    – Michael Dorgan
    10 hours ago






  • 5





    use cdecl

    – Antti Haapala
    9 hours ago














8












8








8


2






I am trying to really understand function pointers without using typedef but cannot seem to get this. I do not understand what signature is needed to convey that I return a pointer to a pointer to a function.



#include <stdio.h>

void odd() printf("odd!n");
void even() printf("even!n");

void (*get_pfn(int i))()

return i % 2 == 0 ? &even : &odd;


__SIGNATURE__

return &get_pfn;


int main()

get_pfn_pfn()(1)();
get_pfn_pfn()(2)();
return 0;



To make this work, what does __SIGNATURE__ have to be?










share|improve this question
















I am trying to really understand function pointers without using typedef but cannot seem to get this. I do not understand what signature is needed to convey that I return a pointer to a pointer to a function.



#include <stdio.h>

void odd() printf("odd!n");
void even() printf("even!n");

void (*get_pfn(int i))()

return i % 2 == 0 ? &even : &odd;


__SIGNATURE__

return &get_pfn;


int main()

get_pfn_pfn()(1)();
get_pfn_pfn()(2)();
return 0;



To make this work, what does __SIGNATURE__ have to be?







c function function-pointers






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 1 hour ago









Justin

15.3k10 gold badges63 silver badges106 bronze badges




15.3k10 gold badges63 silver badges106 bronze badges










asked 10 hours ago









JasJas

5095 silver badges14 bronze badges




5095 silver badges14 bronze badges










  • 5





    Good question - now don't ever do this again. :)

    – Michael Dorgan
    10 hours ago






  • 5





    use cdecl

    – Antti Haapala
    9 hours ago













  • 5





    Good question - now don't ever do this again. :)

    – Michael Dorgan
    10 hours ago






  • 5





    use cdecl

    – Antti Haapala
    9 hours ago








5




5





Good question - now don't ever do this again. :)

– Michael Dorgan
10 hours ago





Good question - now don't ever do this again. :)

– Michael Dorgan
10 hours ago




5




5





use cdecl

– Antti Haapala
9 hours ago






use cdecl

– Antti Haapala
9 hours ago













4 Answers
4






active

oldest

votes


















9
















It has to return a function pointer to a function that takes an int and returns a function pointer:



void (*(*get_pfn_pfn(void))(int))(void) 
return &get_pfn;



more lines:



void (*
(*
get_pfn_pfn(void) // this is our function
)(int i) // this is get_pfn(int)
)(void) // this is odd() or even()

return &get_pfn;



The voids can be omitted, in which case the function pointer points to a function that takes unknown number of parameters. Which is not what you want. To declare a function pointer to a function that takes no arguments, you should add void inside function parameter list. The same way it's best to change get_pfn to void (*get_pfn(int i))(void). For example try calling from get_pfn(1)("some arg", "some other arg");. A C compiler will not give a warning, as empty () denote unknown arguments. To say that function takes no arguments, you have to (void).



For many the sequences of braces, especially ))(, in function pointers are hard to parse. That's why many prefer typedefs for function pointers or types:



typedef void get_pfn_func_t(void); 
get_pfn_func_t *get_pfn(int i)
return i % 2 == 0 ? &even : &odd;


typedef get_pfn_func_t *get_pfn_pfn_func_t(int i);
get_pfn_pfn_func_t *get_pfn_pfn(void)
return &get_pfn;






share|improve this answer






















  • 2





    This one confirmed to work with online C check.

    – Michael Dorgan
    10 hours ago











  • Thank you so so much Kamil!! I like that broken down/visualized tree like view, it helped make it a lot more understandable :) !!

    – Jas
    10 hours ago







  • 1





    @Jas You may like it but I don't think it is recommended to write code in this manner.

    – machine_1
    10 hours ago











  • I wish there was a website that had a GUI representation of a function pointer, let you move various components around, etc. Something like nsdateformatter.com

    – Alexander
    1 hour ago


















4
















The return type of the function get_pfn is -



void (*) ();


So type of &get_pfn is -



void (*(*)(int))()


Now, this function returns this type, hence it's signature will be -



void (*(*(foo)())(int))()


You can verify this by typing this in cdecl.org






share|improve this answer



























  • Thank you very much Ajay! Your explanation breaking down the steps helped me understand it more easily, but unfortunately the signature did not work sorry :(

    – Jas
    10 hours ago






  • 1





    @Jas, sorry I messed up the order of the (int). I thought your odd even functions take a param int. I will correct it.

    – Ajay Brahmakshatriya
    10 hours ago






  • 1





    @Jas, I have corrected my answer,

    – Ajay Brahmakshatriya
    10 hours ago


















2
















Function pointers without a typedef can be tricky to work with. To figure them out, you work from the inside out.



So let's break down exactly how we come up with the correct function signature.



get_pfn_pfn is a function:



get_pfn_pfn()


Which takes no parameters:



get_pfn_pfn(void)


And returns a pointer:



*get_pfn_pfn(void)


To a function:



(*get_pfn_pfn(void))()


Which takes an int parameter:



(*get_pfn_pfn(void))(int)


And returns a pointer:



*(*get_pfn_pfn(void))(int)


To a function:



(*(*get_pfn_pfn(void))(int))()


Which takes no parameters:



(*(*get_pfn_pfn(void))(int))(void)


And returns nothing (i.e. void):



void (*(*get_pfn_pfn(void))(int))(void)



Of course, using typedef's simplifies this greatly.



First the type for even and odd:



typedef void (*func1)(void);


Which we can then apply to get_pfn:



func1 get_pfn(int) ... 


Then the type for this function:



typedef func1 (*func2)(int);


Which we can apply to get_pfn_pfn:



func2 get_pfn_pfn(void) ... 





share|improve this answer


































    1
















    it's this way:



    void (*(*get_pfn_pfn(void))(int))()





    share|improve this answer










    New contributor



    Abdelfettah Besbes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );














      draft saved

      draft discarded
















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f57875417%2fdefining-a-function-which-returns-a-function-pointer-which-also-returns-a-functi%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      9
















      It has to return a function pointer to a function that takes an int and returns a function pointer:



      void (*(*get_pfn_pfn(void))(int))(void) 
      return &get_pfn;



      more lines:



      void (*
      (*
      get_pfn_pfn(void) // this is our function
      )(int i) // this is get_pfn(int)
      )(void) // this is odd() or even()

      return &get_pfn;



      The voids can be omitted, in which case the function pointer points to a function that takes unknown number of parameters. Which is not what you want. To declare a function pointer to a function that takes no arguments, you should add void inside function parameter list. The same way it's best to change get_pfn to void (*get_pfn(int i))(void). For example try calling from get_pfn(1)("some arg", "some other arg");. A C compiler will not give a warning, as empty () denote unknown arguments. To say that function takes no arguments, you have to (void).



      For many the sequences of braces, especially ))(, in function pointers are hard to parse. That's why many prefer typedefs for function pointers or types:



      typedef void get_pfn_func_t(void); 
      get_pfn_func_t *get_pfn(int i)
      return i % 2 == 0 ? &even : &odd;


      typedef get_pfn_func_t *get_pfn_pfn_func_t(int i);
      get_pfn_pfn_func_t *get_pfn_pfn(void)
      return &get_pfn;






      share|improve this answer






















      • 2





        This one confirmed to work with online C check.

        – Michael Dorgan
        10 hours ago











      • Thank you so so much Kamil!! I like that broken down/visualized tree like view, it helped make it a lot more understandable :) !!

        – Jas
        10 hours ago







      • 1





        @Jas You may like it but I don't think it is recommended to write code in this manner.

        – machine_1
        10 hours ago











      • I wish there was a website that had a GUI representation of a function pointer, let you move various components around, etc. Something like nsdateformatter.com

        – Alexander
        1 hour ago















      9
















      It has to return a function pointer to a function that takes an int and returns a function pointer:



      void (*(*get_pfn_pfn(void))(int))(void) 
      return &get_pfn;



      more lines:



      void (*
      (*
      get_pfn_pfn(void) // this is our function
      )(int i) // this is get_pfn(int)
      )(void) // this is odd() or even()

      return &get_pfn;



      The voids can be omitted, in which case the function pointer points to a function that takes unknown number of parameters. Which is not what you want. To declare a function pointer to a function that takes no arguments, you should add void inside function parameter list. The same way it's best to change get_pfn to void (*get_pfn(int i))(void). For example try calling from get_pfn(1)("some arg", "some other arg");. A C compiler will not give a warning, as empty () denote unknown arguments. To say that function takes no arguments, you have to (void).



      For many the sequences of braces, especially ))(, in function pointers are hard to parse. That's why many prefer typedefs for function pointers or types:



      typedef void get_pfn_func_t(void); 
      get_pfn_func_t *get_pfn(int i)
      return i % 2 == 0 ? &even : &odd;


      typedef get_pfn_func_t *get_pfn_pfn_func_t(int i);
      get_pfn_pfn_func_t *get_pfn_pfn(void)
      return &get_pfn;






      share|improve this answer






















      • 2





        This one confirmed to work with online C check.

        – Michael Dorgan
        10 hours ago











      • Thank you so so much Kamil!! I like that broken down/visualized tree like view, it helped make it a lot more understandable :) !!

        – Jas
        10 hours ago







      • 1





        @Jas You may like it but I don't think it is recommended to write code in this manner.

        – machine_1
        10 hours ago











      • I wish there was a website that had a GUI representation of a function pointer, let you move various components around, etc. Something like nsdateformatter.com

        – Alexander
        1 hour ago













      9














      9










      9









      It has to return a function pointer to a function that takes an int and returns a function pointer:



      void (*(*get_pfn_pfn(void))(int))(void) 
      return &get_pfn;



      more lines:



      void (*
      (*
      get_pfn_pfn(void) // this is our function
      )(int i) // this is get_pfn(int)
      )(void) // this is odd() or even()

      return &get_pfn;



      The voids can be omitted, in which case the function pointer points to a function that takes unknown number of parameters. Which is not what you want. To declare a function pointer to a function that takes no arguments, you should add void inside function parameter list. The same way it's best to change get_pfn to void (*get_pfn(int i))(void). For example try calling from get_pfn(1)("some arg", "some other arg");. A C compiler will not give a warning, as empty () denote unknown arguments. To say that function takes no arguments, you have to (void).



      For many the sequences of braces, especially ))(, in function pointers are hard to parse. That's why many prefer typedefs for function pointers or types:



      typedef void get_pfn_func_t(void); 
      get_pfn_func_t *get_pfn(int i)
      return i % 2 == 0 ? &even : &odd;


      typedef get_pfn_func_t *get_pfn_pfn_func_t(int i);
      get_pfn_pfn_func_t *get_pfn_pfn(void)
      return &get_pfn;






      share|improve this answer















      It has to return a function pointer to a function that takes an int and returns a function pointer:



      void (*(*get_pfn_pfn(void))(int))(void) 
      return &get_pfn;



      more lines:



      void (*
      (*
      get_pfn_pfn(void) // this is our function
      )(int i) // this is get_pfn(int)
      )(void) // this is odd() or even()

      return &get_pfn;



      The voids can be omitted, in which case the function pointer points to a function that takes unknown number of parameters. Which is not what you want. To declare a function pointer to a function that takes no arguments, you should add void inside function parameter list. The same way it's best to change get_pfn to void (*get_pfn(int i))(void). For example try calling from get_pfn(1)("some arg", "some other arg");. A C compiler will not give a warning, as empty () denote unknown arguments. To say that function takes no arguments, you have to (void).



      For many the sequences of braces, especially ))(, in function pointers are hard to parse. That's why many prefer typedefs for function pointers or types:



      typedef void get_pfn_func_t(void); 
      get_pfn_func_t *get_pfn(int i)
      return i % 2 == 0 ? &even : &odd;


      typedef get_pfn_func_t *get_pfn_pfn_func_t(int i);
      get_pfn_pfn_func_t *get_pfn_pfn(void)
      return &get_pfn;







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited 10 hours ago

























      answered 10 hours ago









      Kamil CukKamil Cuk

      21.5k2 gold badges9 silver badges37 bronze badges




      21.5k2 gold badges9 silver badges37 bronze badges










      • 2





        This one confirmed to work with online C check.

        – Michael Dorgan
        10 hours ago











      • Thank you so so much Kamil!! I like that broken down/visualized tree like view, it helped make it a lot more understandable :) !!

        – Jas
        10 hours ago







      • 1





        @Jas You may like it but I don't think it is recommended to write code in this manner.

        – machine_1
        10 hours ago











      • I wish there was a website that had a GUI representation of a function pointer, let you move various components around, etc. Something like nsdateformatter.com

        – Alexander
        1 hour ago












      • 2





        This one confirmed to work with online C check.

        – Michael Dorgan
        10 hours ago











      • Thank you so so much Kamil!! I like that broken down/visualized tree like view, it helped make it a lot more understandable :) !!

        – Jas
        10 hours ago







      • 1





        @Jas You may like it but I don't think it is recommended to write code in this manner.

        – machine_1
        10 hours ago











      • I wish there was a website that had a GUI representation of a function pointer, let you move various components around, etc. Something like nsdateformatter.com

        – Alexander
        1 hour ago







      2




      2





      This one confirmed to work with online C check.

      – Michael Dorgan
      10 hours ago





      This one confirmed to work with online C check.

      – Michael Dorgan
      10 hours ago













      Thank you so so much Kamil!! I like that broken down/visualized tree like view, it helped make it a lot more understandable :) !!

      – Jas
      10 hours ago






      Thank you so so much Kamil!! I like that broken down/visualized tree like view, it helped make it a lot more understandable :) !!

      – Jas
      10 hours ago





      1




      1





      @Jas You may like it but I don't think it is recommended to write code in this manner.

      – machine_1
      10 hours ago





      @Jas You may like it but I don't think it is recommended to write code in this manner.

      – machine_1
      10 hours ago













      I wish there was a website that had a GUI representation of a function pointer, let you move various components around, etc. Something like nsdateformatter.com

      – Alexander
      1 hour ago





      I wish there was a website that had a GUI representation of a function pointer, let you move various components around, etc. Something like nsdateformatter.com

      – Alexander
      1 hour ago













      4
















      The return type of the function get_pfn is -



      void (*) ();


      So type of &get_pfn is -



      void (*(*)(int))()


      Now, this function returns this type, hence it's signature will be -



      void (*(*(foo)())(int))()


      You can verify this by typing this in cdecl.org






      share|improve this answer



























      • Thank you very much Ajay! Your explanation breaking down the steps helped me understand it more easily, but unfortunately the signature did not work sorry :(

        – Jas
        10 hours ago






      • 1





        @Jas, sorry I messed up the order of the (int). I thought your odd even functions take a param int. I will correct it.

        – Ajay Brahmakshatriya
        10 hours ago






      • 1





        @Jas, I have corrected my answer,

        – Ajay Brahmakshatriya
        10 hours ago















      4
















      The return type of the function get_pfn is -



      void (*) ();


      So type of &get_pfn is -



      void (*(*)(int))()


      Now, this function returns this type, hence it's signature will be -



      void (*(*(foo)())(int))()


      You can verify this by typing this in cdecl.org






      share|improve this answer



























      • Thank you very much Ajay! Your explanation breaking down the steps helped me understand it more easily, but unfortunately the signature did not work sorry :(

        – Jas
        10 hours ago






      • 1





        @Jas, sorry I messed up the order of the (int). I thought your odd even functions take a param int. I will correct it.

        – Ajay Brahmakshatriya
        10 hours ago






      • 1





        @Jas, I have corrected my answer,

        – Ajay Brahmakshatriya
        10 hours ago













      4














      4










      4









      The return type of the function get_pfn is -



      void (*) ();


      So type of &get_pfn is -



      void (*(*)(int))()


      Now, this function returns this type, hence it's signature will be -



      void (*(*(foo)())(int))()


      You can verify this by typing this in cdecl.org






      share|improve this answer















      The return type of the function get_pfn is -



      void (*) ();


      So type of &get_pfn is -



      void (*(*)(int))()


      Now, this function returns this type, hence it's signature will be -



      void (*(*(foo)())(int))()


      You can verify this by typing this in cdecl.org







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited 10 hours ago

























      answered 10 hours ago









      Ajay BrahmakshatriyaAjay Brahmakshatriya

      7,2453 gold badges16 silver badges36 bronze badges




      7,2453 gold badges16 silver badges36 bronze badges















      • Thank you very much Ajay! Your explanation breaking down the steps helped me understand it more easily, but unfortunately the signature did not work sorry :(

        – Jas
        10 hours ago






      • 1





        @Jas, sorry I messed up the order of the (int). I thought your odd even functions take a param int. I will correct it.

        – Ajay Brahmakshatriya
        10 hours ago






      • 1





        @Jas, I have corrected my answer,

        – Ajay Brahmakshatriya
        10 hours ago

















      • Thank you very much Ajay! Your explanation breaking down the steps helped me understand it more easily, but unfortunately the signature did not work sorry :(

        – Jas
        10 hours ago






      • 1





        @Jas, sorry I messed up the order of the (int). I thought your odd even functions take a param int. I will correct it.

        – Ajay Brahmakshatriya
        10 hours ago






      • 1





        @Jas, I have corrected my answer,

        – Ajay Brahmakshatriya
        10 hours ago
















      Thank you very much Ajay! Your explanation breaking down the steps helped me understand it more easily, but unfortunately the signature did not work sorry :(

      – Jas
      10 hours ago





      Thank you very much Ajay! Your explanation breaking down the steps helped me understand it more easily, but unfortunately the signature did not work sorry :(

      – Jas
      10 hours ago




      1




      1





      @Jas, sorry I messed up the order of the (int). I thought your odd even functions take a param int. I will correct it.

      – Ajay Brahmakshatriya
      10 hours ago





      @Jas, sorry I messed up the order of the (int). I thought your odd even functions take a param int. I will correct it.

      – Ajay Brahmakshatriya
      10 hours ago




      1




      1





      @Jas, I have corrected my answer,

      – Ajay Brahmakshatriya
      10 hours ago





      @Jas, I have corrected my answer,

      – Ajay Brahmakshatriya
      10 hours ago











      2
















      Function pointers without a typedef can be tricky to work with. To figure them out, you work from the inside out.



      So let's break down exactly how we come up with the correct function signature.



      get_pfn_pfn is a function:



      get_pfn_pfn()


      Which takes no parameters:



      get_pfn_pfn(void)


      And returns a pointer:



      *get_pfn_pfn(void)


      To a function:



      (*get_pfn_pfn(void))()


      Which takes an int parameter:



      (*get_pfn_pfn(void))(int)


      And returns a pointer:



      *(*get_pfn_pfn(void))(int)


      To a function:



      (*(*get_pfn_pfn(void))(int))()


      Which takes no parameters:



      (*(*get_pfn_pfn(void))(int))(void)


      And returns nothing (i.e. void):



      void (*(*get_pfn_pfn(void))(int))(void)



      Of course, using typedef's simplifies this greatly.



      First the type for even and odd:



      typedef void (*func1)(void);


      Which we can then apply to get_pfn:



      func1 get_pfn(int) ... 


      Then the type for this function:



      typedef func1 (*func2)(int);


      Which we can apply to get_pfn_pfn:



      func2 get_pfn_pfn(void) ... 





      share|improve this answer































        2
















        Function pointers without a typedef can be tricky to work with. To figure them out, you work from the inside out.



        So let's break down exactly how we come up with the correct function signature.



        get_pfn_pfn is a function:



        get_pfn_pfn()


        Which takes no parameters:



        get_pfn_pfn(void)


        And returns a pointer:



        *get_pfn_pfn(void)


        To a function:



        (*get_pfn_pfn(void))()


        Which takes an int parameter:



        (*get_pfn_pfn(void))(int)


        And returns a pointer:



        *(*get_pfn_pfn(void))(int)


        To a function:



        (*(*get_pfn_pfn(void))(int))()


        Which takes no parameters:



        (*(*get_pfn_pfn(void))(int))(void)


        And returns nothing (i.e. void):



        void (*(*get_pfn_pfn(void))(int))(void)



        Of course, using typedef's simplifies this greatly.



        First the type for even and odd:



        typedef void (*func1)(void);


        Which we can then apply to get_pfn:



        func1 get_pfn(int) ... 


        Then the type for this function:



        typedef func1 (*func2)(int);


        Which we can apply to get_pfn_pfn:



        func2 get_pfn_pfn(void) ... 





        share|improve this answer





























          2














          2










          2









          Function pointers without a typedef can be tricky to work with. To figure them out, you work from the inside out.



          So let's break down exactly how we come up with the correct function signature.



          get_pfn_pfn is a function:



          get_pfn_pfn()


          Which takes no parameters:



          get_pfn_pfn(void)


          And returns a pointer:



          *get_pfn_pfn(void)


          To a function:



          (*get_pfn_pfn(void))()


          Which takes an int parameter:



          (*get_pfn_pfn(void))(int)


          And returns a pointer:



          *(*get_pfn_pfn(void))(int)


          To a function:



          (*(*get_pfn_pfn(void))(int))()


          Which takes no parameters:



          (*(*get_pfn_pfn(void))(int))(void)


          And returns nothing (i.e. void):



          void (*(*get_pfn_pfn(void))(int))(void)



          Of course, using typedef's simplifies this greatly.



          First the type for even and odd:



          typedef void (*func1)(void);


          Which we can then apply to get_pfn:



          func1 get_pfn(int) ... 


          Then the type for this function:



          typedef func1 (*func2)(int);


          Which we can apply to get_pfn_pfn:



          func2 get_pfn_pfn(void) ... 





          share|improve this answer















          Function pointers without a typedef can be tricky to work with. To figure them out, you work from the inside out.



          So let's break down exactly how we come up with the correct function signature.



          get_pfn_pfn is a function:



          get_pfn_pfn()


          Which takes no parameters:



          get_pfn_pfn(void)


          And returns a pointer:



          *get_pfn_pfn(void)


          To a function:



          (*get_pfn_pfn(void))()


          Which takes an int parameter:



          (*get_pfn_pfn(void))(int)


          And returns a pointer:



          *(*get_pfn_pfn(void))(int)


          To a function:



          (*(*get_pfn_pfn(void))(int))()


          Which takes no parameters:



          (*(*get_pfn_pfn(void))(int))(void)


          And returns nothing (i.e. void):



          void (*(*get_pfn_pfn(void))(int))(void)



          Of course, using typedef's simplifies this greatly.



          First the type for even and odd:



          typedef void (*func1)(void);


          Which we can then apply to get_pfn:



          func1 get_pfn(int) ... 


          Then the type for this function:



          typedef func1 (*func2)(int);


          Which we can apply to get_pfn_pfn:



          func2 get_pfn_pfn(void) ... 






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 10 hours ago

























          answered 10 hours ago









          dbushdbush

          112k15 gold badges127 silver badges159 bronze badges




          112k15 gold badges127 silver badges159 bronze badges
























              1
















              it's this way:



              void (*(*get_pfn_pfn(void))(int))()





              share|improve this answer










              New contributor



              Abdelfettah Besbes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.

























                1
















                it's this way:



                void (*(*get_pfn_pfn(void))(int))()





                share|improve this answer










                New contributor



                Abdelfettah Besbes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.























                  1














                  1










                  1









                  it's this way:



                  void (*(*get_pfn_pfn(void))(int))()





                  share|improve this answer










                  New contributor



                  Abdelfettah Besbes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  it's this way:



                  void (*(*get_pfn_pfn(void))(int))()






                  share|improve this answer










                  New contributor



                  Abdelfettah Besbes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.








                  share|improve this answer



                  share|improve this answer








                  edited 10 hours ago





















                  New contributor



                  Abdelfettah Besbes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.








                  answered 10 hours ago









                  Abdelfettah BesbesAbdelfettah Besbes

                  31110 bronze badges




                  31110 bronze badges




                  New contributor



                  Abdelfettah Besbes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.




                  New contributor




                  Abdelfettah Besbes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.

































                      draft saved

                      draft discarded















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f57875417%2fdefining-a-function-which-returns-a-function-pointer-which-also-returns-a-functi%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                      Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                      199年 目錄 大件事 到箇年出世嗰人 到箇年死嗰人 節慶、風俗習慣 導覽選單