Subject: void main
To: Jonathan Stone <>
From: Alan Barrett <>
List: current-users
Date: 03/27/1996 15:19:45
> Two of the main()s that were changed recently was named/ns_main.c and
> named-xfer/named-xfer.c.

I have reported that bug to the maintainer of BIND.

> Those programs were (I assume, deliberately) written to avoid
> returning from main(). They consistently use exit() instead.  The end
> of main() is marked with /*NOTREACHED*/ for lint.

Yes, I expect that that was all deliberate, and it's perfectly
legitimate; but declaring main() as returning void is simply wrong (if
the program is intended to be processed by a standard C compiler in a
hosted environment).  There's no reason to gratuitously write C code
that invokes undefined behaviour, when it's so easy to write strongly
conforming code instead.  (There are sometimes legitimate reasons
for writing nonstandard code, but "void main" is not one of those

> I think there are perfectly reasonable arguments for declaring main()
> as returning void in such circumstances.  It tells both the compiler,
> and future maintainers, what that _particular_ main() is intended to
> do.

No, it tells both the compiler and future maintainers that the programmer
did not understand the ANSI/ISO C Standard, or deliberately chose not to
write code for a hosted standard C environment.  Comments might help
future maintainers tell which of the two cases hold. 

> There's one very important principle at stake here that I haven't seen
> explicitly addressed.  That principle is that ``third-party'' software
> in the NetBSD tree should be kept as close as possible to the third
> party's original version -- at least, if the third party is actually
> maintaining that software.

I agree.  And in many cases, the appropriate action is to pass local
enhancements and bug fixes back to the maintainer.

--apb (Alan Barrett)