The main() function

Updated: April 19, 2023

The first thing that runs is, of course, main(). You'll notice that my main() functions tend to be very short—handle command-line processing (always with optproc()), call a few initialization functions (if required), and then start processing.

In general, I try to deallocate any memory that I've allocated throughout the course of the program. This might seem like overkill because the operating system cleans up your resources when you drop off the end of main() (or call exit()). Some of the subsystems might find their way into other projects—and they might need to start up and shut down many times during the life of the process. Keeping things tidy makes it easier to reuse code. It also helps when using tools like the debug malloc() library.