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,877 of 243,242   
   Andrey Tarasevich to Kaz Kylheku   
   Re: function pointer question   
   07 Jan 26 07:18:31   
   
   From: noone@noone.net   
      
   On Tue 1/6/2026 12:41 PM, Kaz Kylheku wrote:   
   >>>   
   >>> 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;   
   >   
   > Butlonly because operation is a function type, so the concept of   
   > a tentative definition doesn't apply.   
      
   Yes, to me it feels like it has way less potential to mislead with an   
   `extern`. But I can't really say whether this perception is objectively   
   inherent in the construct, or it is just the fact that it is an exotic   
   way of declaring functions (for me and, probably, for most people).   
      
   However, while it is true that the concept of a tentative definition   
   doesn't apply, I still don't quite get your point. What if were an   
   object type and the concept would apply? Are you implying that tentative   
   definitions should be avoided (i.e. that all object definitions should   
   include an initializer)?   
      
   > The lack of extern could trip someone up who refactors the   
   > code such that the operations are object types:   
   >   
   >    named_operation add, sub, mul, div; // oops, multiple definition   
   >   
   >    static named_operation ops[] = { add, sub, mul, div };   
      
   Again, I'm at a bit of a loss. What is this intended to illustrate?   
      
   --   
   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