News for hackers. Stuff that matters.
Re:What happens before main() is executed in C and why is it... by dvirsky on Friday May 04, 2018 @03:41PM (#16997581)
you can have pre-main functions in in C as well (as a GCC extension). If you define functions with `__attribute__(constructor)` and they will be called before main(). You can even set the priority on them, and set post-main destructor callbacks. This works even for shared libraries loaded in run-time.

I've used this as a trick to automatically run unit tests, though, not for any real work.

Re:What happens before main() is executed in C and why is it... by bakztfutur3 on Friday May 04, 2018 @04:11PM (#16997868)
"Yeah, yeah, but your scientists were so preoccupied with whether or not they could that they didn't stop to think if they should."
Re:What happens before main() is executed in C and why is it... by dvirsky on Friday May 04, 2018 @04:15PM (#16997901)
It can be useful for registering things automatically, like Go's init() functions which I've used on occasion.