News for hackers. Stuff that matters.
Re:What happens before main() is executed in C and why is it... by pdpi on Friday May 04, 2018 @01:53PM (#16996650)
> relying on static initialization is something one should think about potentially solving differently

This is such a notorious problem, it even has a name: Static Initialisation Order Fiasco (see: https://isocpp.org/wiki/faq/ctors#static-init-order)

The symmetrical Static Destruction Order Fiasco is also a very fun problem to deal with. The solution proposed for SIOF in the C++ FAQ does nothing to help you deal with this one, though.

Re:What happens before main() is executed in C and why is it... by pcwalton on Friday May 04, 2018 @02:23PM (#16996942)
Perhaps worse, lots of new languages, for example Go, copied this mistake from C++. :(
Re:What happens before main() is executed in C and why is it... by helper on Friday May 04, 2018 @03:49PM (#16997652)
Is the "static initialization order fiasco" a thing that can happen in go? The order of package level variable initialization is well defined in the spec and because go doesn't allow import cycles it seems like the issue mentioned in the linked page is not possible.
Re:What happens before main() is executed in C and why is it... by pcwalton on Friday May 04, 2018 @03:57PM (#16997731)
Static initialization order may be defined, but that doesn't mean it's easy to reason about.
Re:What happens before main() is executed in C and why is it... by pjmlp on Friday May 04, 2018 @04:52PM (#16998218)
Actually, if you mean package initialization blocks, they were already present in Mesa derived languages.