Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: function pointer question Date: Sat, 03 Jan 2026 16:48:08 -0800 Organization: None to speak of Lines: 34 Message-ID: <871pk64307.fsf@example.invalid> References: <10j7rs6$7c9e$1@dont-email.me> <20260102091518.226@kylheku.com> <10j96mn$jrsp$1@dont-email.me> <10jc4n0$1ijf2$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Sun, 04 Jan 2026 00:48:10 +0000 (UTC) Injection-Info: dont-email.me; posting-host="897b51646efb7ad5c94af47762914063"; logging-data="1740026"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+2AGH58zfGYVMjE9dHZZb9" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:VJVj2B6WruAAAEivZ2p9Q/lSPKo= sha1:z57WUw2PXPCdNDAO1bidTDbYgfE= Xref: csiph.com comp.lang.c:396131 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 */