In GCC-compiled code, constructors for classes without virtual base classes may appear duplicated in library listings, raising questions about the reasons behind this behavior. To elaborate, the Itanium C ABI defines a set of naming conventions for C symbols, including constructors.
Let's examine the mangled names of these constructors:
As you can see, the constructors are distinguished by the C1 (complete object constructor) and C2 (base object constructor) suffixes.
This duality stems from polymorphism support, although it is not strictly required in this case. The complete object constructor additionally initializes virtual base classes, while the base object constructor initializes data members and non-virtual base classes.
Despite multiple entries in library listings, these duplicate constructors do not cause "multiple definition of symbol __" errors. This is because the ABI provides unique mangled names for each constructor type, ensuring that they are treated as distinct symbols by the linker.
The dual emission of constructor symbols in GCC-compiled code is a result of polymorphism support and the Itanium C ABI naming conventions. Understanding these concepts illuminates the reasons behind this behavior and addresses any concerns about multiple definitions.
The above is the detailed content of Why do constructors for classes without virtual base classes appear duplicated in GCC-compiled code?. For more information, please follow other related articles on the PHP Chinese website!