Home  >  Article  >  Backend Development  >  Why Are There Two Symbols for C Constructors?

Why Are There Two Symbols for C Constructors?

Linda Hamilton
Linda HamiltonOriginal
2024-11-24 02:41:09267browse

Why Are There Two Symbols for C   Constructors?

Dual Symbols for C Constructors

The Itanium C ABI specifies that mangled names of constructors include information about their type and parameters. Accordingly, the two constructor entries observed in libraries stem from their different constructor types:

  • Complete Object Constructor (C1): This constructor fully initializes the object, including any virtual base classes.
  • Base Object Constructor (C2): This constructor initializes the object itself, along with data members and non-virtual base classes.

Dual Symbols and Multiple Definition Errors

Despite having dual entries, conflicting symbol definitions do not arise due to the use of the C1 and C2 suffixes. The ABI ensures that the mangled names are unique, providing compiler support for handling these two constructor types differently.

Additional Details

  • In the absence of virtual base classes, the complete and base object constructors are identical, and the symbols may be aliased to the same code under sufficient optimization.
  • The need for dual constructor symbols is primarily driven by support for polymorphism, where different objects may inherit different base classes, requiring specialized initialization.
  • This behavior was once displayed in c filt output but is no longer included.

The above is the detailed content of Why Are There Two Symbols for C Constructors?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn