Home > Mobile >  What is the relation between C storage-class and C destructor
What is the relation between C storage-class and C destructor

Time:10-06

I am very new to C/C programming.

  • Storage class in C signifies the visibility and life cycle of a variable.

  • In C , Constructor and Destructor are used to initialize & release-resources the object occupied.

Yes, constructor helps reducing much of repetitive code but destructors are used to release and/or free resources (once an object goes out of scope).

Are these concepts coupled in some way in their implementation?

CodePudding user response:

For C Storage classes see: https://stackoverflow.com/a/2661411/8740349

Let's not talk about implementions, as each compiler works differently, but if you ask about C spec, most keywords mean the same.

Except that:

  • register keyword was removed since C 17 (after being deprecated in C 11), without any alternative.
  • auto means to auto-detect type, like:
auto myVariable = myFunction("blablabla (how old are you, in Chinese)");

Is destructor related to storage-class?

No, C Class and/or Struct is destructed before it's storage is deallocated.

As mentioned in comments: Handling deallocation of storage isn't the subject of the destructor but the subject of the respective "deallocator" (provided by the compiler e.g. for global and local variables or the delete for memory allocated with new).

  •  Tags:  
  • c c
  • Related