Re:Who Needs Main() Anyway?
by xjwm on Saturday January 21, 2023 @10:05AM
(#34466871)
I've written code like this in C to create library functions that will be linked in to other projects, but where there is no 'main' function in the C file. Do people use C++ the same way, or is it best practice to include 'main?'
Re:Who Needs Main() Anyway?
by MathMonkeyMan on Saturday January 21, 2023 @12:58PM
(#34468448)
It's the same as in C. The observation here is that variables with static storage duration can be initialized by running user code before main() begins.
It’s a surprising thing when one first discovers it, but it makes a lot of sense.
https://artificial-mind.net/blog/2020/10/17/static-registrat... gives a good overview.
[1] : https://progforperf.github.io/Expert_C_Programming.pdf
Just read Hongjiu Lu's classic paper ELF: From The Programmer's Perspective to get an idea of how everything comes together in C/C++ land.
edit: COFF phoneticly eqivalent to cough.