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,753 of 243,242   
   Keith Thompson to James Kuyper   
   Re: function pointer question   
   03 Jan 26 16:48:08   
   
   From: Keith.S.Thompson+u@gmail.com   
      
   James Kuyper  writes:   
   [...]   
   > Similarly, in C, the declaration "int foo()" is an old-style K&R   
   > declaration that says that foo is a function that takes an unspecified   
   > number of arguments of unspecified types. K&R declarations were found to   
   > be too error-prone, but the language still allows them for backwards   
   > compatibility. When C was first standardized, K&R declarations were   
   > replace with prototype declarations which specified the type of each   
   > argument, which allowed error checking.   
   > The natural way for a prototype declaration to say "no arguments" would   
   > have been to simply specify no arguments, and C++ uses that approach.   
   > However, since C still supports the old K&R declarations, a different   
   > method was used. "int foo(void)" is a function prototype that says that   
   > foo doesn't take any arguments.   
   [...]   
      
   Some of this changed in C23.  I don't have all the details off the top   
   of my head, but as I understand it old-style function definitions   
   are no longer allowed and `int foo()` is equivalent to `int foo(void)`.   
      
   (Which means, I think, that my argument that `int main()` has undefined   
   behavior does not apply in C23.)   
      
   It's still not a bad idea to write (void) on a parameterless function   
   declaration/definition unless you're sure your code will be compiled   
   only with a compiler that implements C23 or later.   
      
   The 2023 ISO C standard is expensive, but the closest draft is:   
      
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf   
      
   --   
   Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com   
   void Void(void) { Void(); } /* The recursive call of the 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