3 ms·
`main` is the default entrypoint, with one simple argument to the linker you can change entrypoint symbol to whatever you wish. You can add `premain` function
by friendzis 2y ago
`main` is the default entrypoint, with one simple argument to the linker you can change entrypoint symbol to whatever you wish.
You can add `premain` function that calls `main` and set it as an entrypoint, you can implement pre-start logic in main and call main loop later.
This is how any sane program is written anyway: set up environment -> continue with business logic
- account42 2y agomain() is not the entry pont, some platform specific CRT is.
- skissane 2y agoAlso, the CRT will call any functions you declare `__attribute__((constructor))` before it calls `main()`
- dietr1ch 2y agoI know I can fool around with crt0, but I'm not sure how much you can really use that if you plan to use libraries that may depend on global `static` things that get created as they are linked in before `main` starts. Maybe it's possible, but if I need to review every library (and hope they don't break my assumptions later) I think I lost on building this separation in practical way.