When communicating objects that initialize prior to main()
, we usually refer to that as "static initialization". Is there a standard terminology for the opposite of that, something like "static de-initialization"? This would refer to when those static objects are destroyed (after exiting main()
).

- 171,901
- 28
- 288
- 402

- 24,859
- 31
- 132
- 243
-
almost a dupe: https://stackoverflow.com/questions/2204608/does-c-call-destructors-for-global-and-class-static-variables – 463035818_is_not_an_ai Sep 17 '18 at 15:01
-
1@Ron when do static objects "leave scope" ? – 463035818_is_not_an_ai Sep 17 '18 at 15:02
-
@user463035818 When the program terminates? But you have a point. – Ron Sep 17 '18 at 15:03
-
Other almost dupe https://stackoverflow.com/questions/469597/destruction-order-of-static-objects-in-c – Öö Tiib Sep 17 '18 at 15:04
-
There are different circumstances in which objects are initialised, hence the terms "static initalisation", "dynamic initialisation", etc which affect the manner of initialisation. However, the destruction of objects only occurs in one way - it's lifetime ends and the object is destroyed (destructor invoked). So there are not distinct terms to describe (say) "destruction of a statically initialised object" versus "destruction of a dynamically initialised object", because the process is the same in all cases. An overall term would be "object lifetime ending" or "destruction". – Peter Sep 17 '18 at 15:16
3 Answers
The problem here is you are trying to describe the processes in terms of a functional perspective. This does not work for C++ as we don't have a concept of "static initialization" or functions/code that is run prior to main()
.
In C++ the way to run code before/after main()
is via the construction/destruction of objects. So you have to describe the processes in terms of these concepts.
What you term "static initialization" is in fact the construction of static storage duration objects. Now when you use this phrase C++ programmers will instantly recognize it and wince (because of all the associated complexities that you have to know about).
The oppose of this is: the destruction of static storage duration objects.
These are the terms you should be using.
These will convey the exact meaning you are looking for to other experiences programmers.
Further details about storage duration objects:
There are 4 types of object in C++.
- Static Storage Duration Objects
- Dynamic Storage Duration Objects
- Automatic Storage Duration Objects
- Thread Storage Duration Objects.
Each type has a specific time when it is created and destroyed.
In addition there are rules on if the underlying memory is initialized to zero first.
Then there are rules on when the objects constructor/destructor are called (if the objects type has constructors/destructors).
Static Storage Duration Objects
For "Static Storage Duration" objects they can be constructed before main. But it is a bit more complicated than that (as some are lazily constructed when needed, while others are only constructed after a namespace is accessed).
BUT the order of destruction is 100% well defined. It is the exact opposite order of construction. So all "Static Storage Duration" objects will be destroyed (after main has finished) in the exact opposite order of there construction. When the object is destroyed its destructor is called (if it has one).

- 257,169
- 86
- 333
- 562
-
1
-
@Barmar is correct. I am simply looking for useful terminology to use in conversation. Often times I need to describe when objects are destroyed after `main` exits, and I'm not sure the best way to do that. – void.pointer Sep 17 '18 at 15:07
-
@Barmar: The word void.pointer is looking for is "Static Storage Duration" objects. This conveys the exact type of object you want to talk about. It is then destroyed and if appropriate its destructor is called. There is no such thing as static initialization/destruction it is **ALL** controlled via the type of object. – Martin York Sep 17 '18 at 15:08
-
1He's not looking for the word for the object, but the word for the process that de-initializes it when the program exits. – Barmar Sep 17 '18 at 15:10
-
@Barmar. As I said. There is no word for the processes. It is all controlled via the type of the object. So the way to talk about it is via the type of the object. – Martin York Sep 17 '18 at 15:11
-
We also don't use the term "Static Initializer" in C++. So that is wrong also. – Martin York Sep 17 '18 at 15:13
-
The destruction order is not 100% well defined for objects across translation units. Also, while I won't say you're incorrect, I think there are more pragmatic ways of explaining this type of destruction behavior, such as "static destruction", that are still technically correct but make communication easier. Speaking a verbose sentence for the sake of technical conciseness could be more harmful than helpful when trying to make a point. I never have to explain "static initialization" to people. It may not have any basis in the standard but generally people understand what it means. – void.pointer Sep 17 '18 at 17:53
-
@void.pointer You are completely wrong. The order of destruction is 100% well defined for all objects. **EVEN** for objects in different translation units. It is the exact opposite of the order of construction. This is explicitly stated in the standard. – Martin York Sep 17 '18 at 18:12
-
@void.pointer I also think that what you think is pragmatics is naive at best. When actually talking with experienced programmers you will need to clarify as this statement is far from clear. Just because you think they think you know what you mean does not mean you have conveyed the meaning correctly, just that they have come to a conclusion (but you have no idea if they came to the correct one). – Martin York Sep 17 '18 at 18:15
-
@void.pointer If you use the correct terminology. Then people will be able to tell you how to avoid any issues with order of construction. Also they will be able to inform you about how to enforce a particular order of destructor and most importantly of all you will be able to search Stack Overflow and get meaningful results. Use the wrong term and none of this will be available to you. Or at least they will be much more difficult. – Martin York Sep 17 '18 at 18:20
-
You are right, I meant that destruction order is non-deterministic because construction order is non-deterministic. Thank you for clarifying. However, I will still not agree to your interpretation and description of what I'm trying to communicate. I will delegate to the other responses as more pragmatic answers. I find, in practice, most people you work with in the industry are not as knowledgeable of the standard as you are. Even if you explain it as you suggest, usually it requires clarification anyway. There's no way around that. And that's also not the issue I'm trying to solve. – void.pointer Sep 17 '18 at 18:51
-
@void.pointer Yes the order of initialization of static storage duration objects across CU is technically undefined. **BUT** it is really easy to enforce an order **EVEN** across compilation units with one simple trick. Now if you use the correct term an search stack overflow you will find it. – Martin York Sep 19 '18 at 15:13
Regardless of whether the object is static or dynamic, the action that's occurring when the destructor is called is "destruction".
This particular case would then be "static object destruction", the opposite of "static object initialization".

- 741,623
- 53
- 500
- 612
-
Destruction is the correct term. But by itself is not accurate enough to describe the processes of destruction that happens after main. As a result you will need to explain the context in which the destruction happens. – Martin York Sep 17 '18 at 15:51
-
Its actually static storage objects that are in the global scope. If you want to be prcise. – Martin York Sep 17 '18 at 15:54
-
-
@Balmer: No. But there are static storage duration objects that are not initialized before `main()`. – Martin York Sep 17 '18 at 16:02
I would call it "static constructor" and "static destructor". It's easier to pronounce than "de-initialization".

- 733
- 6
- 16
-
So "static initialization" and "static destruction" work? e.g. "This singleton is statically destructed"? – void.pointer Sep 17 '18 at 15:08
-
I would not mix it. Stay with "...struction" on both sides. "This singleton is statically destructed" is totally fine in my opinion. – FLUXparticle Sep 17 '18 at 15:11
-
1Unfortunately no good C++ programmer would use that term. Therefore you will to explain what you mean using standard concepts. There is no point in making up your own terminolgy if you have to explain it every time you use it. Programming is about being exact. Which means using the correct standard terminology. Otherwise you will just waster time re-expliaing yourself using the standard terminology (or you will be imprecise and end up speaking cross wise with another programmer and introducing hidden bugs). – Martin York Sep 17 '18 at 15:50
-
I disagree that the measure of a good programmer is based on usage of certain terminology. It's also not a useful thing to say, since I don't see how that relates to the point of my question. I also think that your viewpoint is not pragmatic. I think we have lots of needs to explain things that aren't part of the language itself, and are really just things that we do with the language. For example, the reason design patterns exist, and UML, to explain common patterns and practices. – void.pointer Sep 17 '18 at 17:47