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?
Historical notes: In the, (very), old days, you could even define 'main' as a
character array rather than a function, and embed machine code in it. There
were a few practical uses of this to make code run differently on different
machines.
> The last one is almost never needed just use getenv(3) if you need to work
> with the environment.
Yes, this is indeed the recommended way to access environment variables now.