3 ms·
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
by dvirsky 8y ago
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.
- bakztfutur3 8y ago"Yeah, yeah, but your scientists were so preoccupied with whether or not they could that they didn't stop to think if they should."
- dvirsky 8y agoIt can be useful for registering things automatically, like Go's init() functions which I've used on occasion.