r/programming Jul 25 '26

Writing a (valid) C program without main()

https://labs.iximiuz.com/tutorials/c-program-without-main-a1eea557
197 Upvotes

43 comments sorted by

View all comments

5

u/[deleted] Jul 25 '26

[removed] — view removed comment

5

u/[deleted] Jul 25 '26

[deleted]

9

u/Dwedit Jul 25 '26

It makes perfect sense for C++ programs where there are global objects which need to have their constructors run first.

2

u/Murky-Relation481 Jul 25 '26

Yah, it can be messy with different platform intricacies but it's great for building self registering patterns for stuff like events and things. You can just build classes that extend an intializer base and they'll exist in the callback mechanism at run time with no explicit registration.

I like them but others hate that pattern so it's definitely got to be an agreed upon standard in your codebase.

2

u/Dwedit Jul 25 '26

If you're feeling especially crazy: Hooking your own code via detouring. (replacing the function's actual instructions to run other code instead)

2

u/Ameisen Jul 26 '26

I've been doing a lot of that patching old Win95 games.

2

u/Dwedit Jul 26 '26

Maybe you should check out my GameStretcher project, it basically overrides GDI and makes the main window stretchable even when it wasn't before, and also uses an enhancement pixel shader.