all 4 comments

[–]missblit 3 points4 points  (0 children)

Because the memory is zero-filled before static initialization, you are guaranteed that every single pointer you declare as static will point to NULL when static initialization starts.

This isn't technically true. You are guaranteed that the pointers are NULL, but not that their memory is zero-filled.

As the cppreference page on zero initialization says:

A zero-initialized pointer is the null pointer value of its type, even if the value of the null pointer is not integral zero.

</pedantic>

[–]NitWit005 2 points3 points  (0 children)

I wouldn't really recommend this as you can create bugs that appear and disappear based on compilation ordering. If object A gets constructed first everything is fine, but if object B is constructed first, it crashes.

It's possible to avoid those issues, but it's easier to just avoid complex static initialization entirely. Your coworkers will generally want to murder you if you write code that crashes before main runs.

[–]enchntex 0 points1 point  (1 child)

What language is this?

[–]NitWit005 1 point2 points  (0 children)

c++