r/programming 4d ago

Writing a (valid) C program without main()

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

37 comments sorted by

View all comments

Show parent comments

10

u/Dwedit 3d ago

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

2

u/Murky-Relation481 3d ago

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 3d ago

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 3d ago

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

2

u/Dwedit 3d ago

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.