On Mon, Mar 09, 2026 at 12:30:01PM +0000, Crystal Kolipe wrote:
> On Mon, Mar 09, 2026 at 06:57:07AM +0100, Claudio Jeker wrote:
> > On Sun, Mar 08, 2026 at 07:14:10PM -0300, Gustavo Rios wrote:
> > > Hi folks!,
> > > 
> > > what is the option of choice for openbsd developer :
> > > 
> > > int main()
> > 
> > This is no longer valid C. This should be int main(void).
> 
> This is an oversimplification.
> 
> I know what you mean, and for the purposes of the OP writing userland code on
> OpenBSD, it's enough.  But for the benefit of other readers of this list who
> might try to extend this to a general observation about C programming, it
> would be good to make it more detailed:
> 
> When an OS provides for main() being the entry point, the main() function is
> supposed to take either no arguments, or exactly two.
> 
> (At least according to all moderately recent C standards.)
> 
> What has changed is that, until recently, defining _any_ function with an
> empty parameter list allowed you to pass a variable number of parameters to
> it.
> 
> So you could do things like:
> 
> int foo()
> {
> return (0);
> }
> 
> int bar()
> {
> foo(1, 2, 3);
> return (0);
> }
> 
> You would get a loud compiler warning, but the code would still compile and
> run.  Doing this has been deprecated since around the time of C11.
> 
> This all comes as a surprise to many people who thought that an empty
> parameter list meant 'no parameters', whereas it actually meant,
> 'unspecified', and the correct way to define a function with no parameters
> was, (and still is):
> 
> int foo(void) {}
> 
> Of course, passing zero parameters to a function that can accept any number,
> (including zero), worked.  But it's better to have things more strictly
> defined so that logic errors can be found at compile time, etc, etc.
> 
> Note that main() is _not_ special in this case.  Any function is treated the
> same way.
> 
> Anyway, recent C standards changed the meaning of an empty parameter list to
> be equivalent to a parameter list with just 'void'.  So the following two
> would be equivalent:
> 
> int foo()
> int foo(void)
> 
> ... and the example code above that called foo() with parameters would throw
> a compiler error rather than just a warning.
> 
> @claudio - has the equivalence of () and (void) been changed in a _very_
> recent version of the C standard that I have not seen?  My understanding is
> that () has not been deprecated, (yet)?  Surely using main() is now perfectly
> valid, (with the new definition), as the previously obsoleted meaning of an
> empty parameter list longer exists?

It is the forcing of foo() to foo(void) that I was referring to. It is a
breaking change in C23 and if you already cleaning up do it right.
The very old K&R function declarations need to die. This one is one of
them (especially when functions are incorrectly declared this way).

I expect compilers will become more and more annoying about these old
constructs. So don't be lazy and add the void.
 
-- 
:wq Claudio

Reply via email to