Home > Article > Backend Development > Do C Destructors Get Called for Global and Static Variables?
Does C Call Destructors for Global and Class Static Variables?
Contrary to some assumptions, C does indeed call destructors for both global and class-static variables. Their destruction occurs at two specific junctures:
It's noteworthy that the order of destruction for these variables mirrors the reverse order of their constructor or dynamic initialization. Furthermore, per § 9.4.2 7, static data members are initialized and destroyed identically to non-local objects.
However, it's important to note that destructors with no observable behavior may not be invoked. This is further explored in Terry Mahaffey's response to "Is a C destructor guaranteed not to be called until the end of the block?"
The above is the detailed content of Do C Destructors Get Called for Global and Static Variables?. For more information, please follow other related articles on the PHP Chinese website!