Home > Backend Development > C++ > Why Are There Two Constructor Symbols in C Libraries?

Why Are There Two Constructor Symbols in C Libraries?

Patricia Arquette
Release: 2024-11-28 17:50:10
Original
699 people have browsed it

Why Are There Two Constructor Symbols in C   Libraries?

Dual Definition of Constructor Symbols in C Libraries

In C , constructor definitions appear twice in libraries when examined with nm. This is due to the Itanium C ABI, which requires multiple constructor entries for polymorphism support.

The mangled names for the constructors indicate their purpose:

  • C1: Complete object constructor
  • C2: Base object constructor

Even though a class may not have virtual base classes, GCC emits both constructors as a result of the ABI's support for polymorphism. This behavior is considered a known issue in GCC, where the compiler could potentially optimize this behavior away when polymorphism is not involved.

The different types of constructors have the following meanings:

  • Complete object constructor: Constructs the entire object, including virtual base classes.
  • Base object constructor: Creates the object itself and initializes data members and non-virtual base classes.
  • Allocating object constructor: Not commonly seen, performs the actions of the complete object constructor and additionally allocates memory using operator new.

While this dual emission of constructor symbols does not typically cause problems, it can lead to confusion when examining library symbols with tools like nm.

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

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template