Post #2835610
2026-05-13 17:06 UTC
@schmerg@mas.to
Static blocks variables are initialized once : https://eel.is/c++draft/stmt.dcl#3
I think this can be surprising but is not one of the more surprising things C++ can throw your way.
Replies (1)
-
@schmerg@mas.to 2026-05-13 17:14
@shafik@hachyderm.io Not that bit but where it's then specifying a default member initialisation and the question is whether the default ctor sets the myCount to one fixed value from one evalaution of counter(), or whether "int myCount = counter();" specifies that counter() should be re-evaluated afresh in the generated ctor (which is what it does). The fact that it worked that way surprised at least 1 senior dev on our team