Elektrine lite

← Feed

@mos_8502@studio8502.ca

Post #3868483

2026-07-16 20:41 UTC

What goes in main()? It's a valid question. There are lots of answers. There's nothing stopping your whole program being one long main function. But if you're looking to make your code maintainable long-term, you'll want to break things up into small, reusable units.

Replies (1)

  • @mos_8502@studio8502.ca 2026-07-16 20:44

    What I do is, I have main.c which (obviously) contains the main() function, but it also contains static functions setup() and quit(), which, respectively, handle setting up the initial program state and cleaning up anything that needs cleaning up before exit. Generally, my main.c looks something like this: #include "foo.h" static void quit() { } static void setup() { } int main(int argc, char **argv) { setup(); // In a GUI program, this is where I'd enter the main loop quit(); }

    Open ##3868482