harmony 鸿蒙C++ Support

  • 2022-08-09
  • 浏览 (891)

C++ Support

Basic Concepts

As one of the most widely used programming languages, C++ supports features, such as classes, encapsulation, and overloading. It is an object-oriented programming language developed based on the C language.

Working Principles

The compiler supports C++ code identification. The system calls the constructors of global objects to perform initialization operations.

Development Guidelines

Available APIs

Table 1 APIs supported by C++

Function

API

Description

Prerequisites for using C++ features

LOS_CppSystemInit

Initializes C++ constructors.

How to Develop

Before using C++ features, you need to call LOS_CppSystemInit to initialize C++ constructors. The initialized constructors are stored in the init_array section, and the section range is passed by the variables __init_array_start__ and __init_array_end__.

Table 2 Parameter description

Parameter

Description

init_array_start

Start of the init_array section

init_array_end

End of the init_array section

NOTE: The LOS_CppSystemInit function must be called before a C++ service. When the C library used by the third-party compiler is not musl libc, some classes or APIs (such as std::thread and std::mutex) that are closely related to system resources have compatibility issues and are not recommended to use.

Development Example

void app_init(void)
{
......
/* Initialize C++ in the startup phase. */
LOS_CppSystemInit((UINTPTR)&__init_array_start__, (UINTPTR)&__init_array_end__);
/* C++ service */
......
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Kernel

harmony 鸿蒙Kernel Coding Specification

harmony 鸿蒙Standard Libraries

harmony 鸿蒙Interrupt Management

harmony 鸿蒙Event

harmony 鸿蒙Mutex

harmony 鸿蒙Queue

harmony 鸿蒙Semaphore

harmony 鸿蒙Doubly Linked List

harmony 鸿蒙Memory Management

0  赞