home bbs files messages ]

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,732 of 243,242   
   Andrey Tarasevich to Ben Bacarisse   
   Re: function pointer question   
   03 Jan 26 07:41:33   
   
   From: noone@noone.net   
      
   On Fri 1/2/2026 7:33 PM, Ben Bacarisse wrote:   
   >   
   > A pattern I've used more than once when setting up a table of function   
   > pointers that act like op-codes.  Maybe you have an add function, a sub   
   > function, a mul functions and a div function.  These are all defined in   
   > a file arithmetic.c, but the table (maybe in another file) needs to see   
   > declarations of the names:   
   >   
   > typedef double operation(double, double);   
   > /* ... */   
   >   
   > extern operation add, sub, mul, div;   
   >   
   > static struct {   
   >      char *name;   
   >      operation *function;   
   > } ops[] = {   
   >      { "add",      add },   
   >      { "subtract", sub },   
   >      { "multiply", mul },   
   >      { "divide",   div }   
   > };   
   >   
      
   ... with a remark that `extern` is completely redundant here.   
      
      operation add, sub, mul, div;   
      
   is already a proper bunch of non-defining function declarations.   
   `extern` does not make it more "non-defining" than it already is.   
      
   --   
   Best regards,   
   Andrey.   
      
   --- 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