Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c    |    Meh, in C you gotta define EVERYTHING    |    243,242 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 242,706 of 243,242    |
|    bart to Michael Sanders    |
|    Re: function pointer question    |
|    02 Jan 26 19:18:56    |
      From: bc@freeuk.com              On 02/01/2026 07:24, Michael Sanders wrote:       > i have:       >       > void moo(char HISTORY[][64], int hst_len, int invalid, const char *gme_msg)       >       > void mastermind(char HISTORY[][64], int hst_len, int invalid, const char       *gme_msg)       >       > to use either i have:       >       > void (*render)(char [][64], int, int, const char *) = MOO ? moo : mastermind;       >       > my multi-part question:       >       > why is void required for the function pointer?       >       > A: because both moo() & mastermind return void?              Neither return anything. But in C there is no special syntax to denote       routines that don't return values. So a dummy 'void' return type is used.              >       > B: because every function must have a return type       > *including function pointers*?              If you have any function that returns type T (including when T is void       like your examples), then its type is 'function(...)returning T'.              A pointer to such a function will have a type:               'pointer to function(...)returning T'.              In C syntax, that return type always goes at the start of the       declaration. In your examples, that will be 'void'.              > C: what about tyedef?              Typedefs create convenient aliases for types. So if you created an alias       U for that pointer type in my last example, then you can subsequently       just use U:               U p, q, r;              This declares three variable all with type 'pointer to ... void'. So in       this case the details are hidden, including that void.              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca