void.pointer
void.pointer

Reputation: 26315

What is the opposite of static initialization?

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()).

Upvotes: 1

Views: 907

Answers (3)

Loki Astari
Loki Astari

Reputation: 264331

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++.

  1. Static Storage Duration Objects
  2. Dynamic Storage Duration Objects
  3. Automatic Storage Duration Objects
  4. 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).

Upvotes: 2

Barmar
Barmar

Reputation: 780698

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".

Upvotes: 1

FLUXparticle
FLUXparticle

Reputation: 1173

I would call it "static constructor" and "static destructor". It's easier to pronounce than "de-initialization".

Upvotes: 0

Related Questions