4 ms·
From the title, I thought this was going to be about the parts of a program that run before the main function is entered. Static objects have to be constructed.
by Animats 1y ago
From the title, I thought this was going to be about the parts of a program that run before the main function is entered. Static objects have to be constructed. Quite a bit of code can run. Order of initialization can be a problem. What happens if you try to do I/O from a static constructor? Does that even work?
- amitprasad 1y agoThis is heavily language runtime dependent — there’s nothing that fundamentally stops you from doing anything during the phase between jumping to an entry point and the main()
- abnercoimbre 1y agoIndeed the craziest among us occasionally abuse this fact, so long as the compiler implementation lets us.
- Animats 1y agoRight. This tends to come up with packages, which just by virtue of being loaded, set up to do something such as log, print, catch errors, or phone home to something.