• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# C++ Support<a name="EN-US_TOPIC_0000001079036442"></a>
2
3-   [Basic Concepts](#section11374125415814)
4-   [Working Principles](#section189351319134418)
5-   [Development Guidelines](#section166302407911)
6    -   [Available APIs](#section1881825119919)
7    -   [How to Develop](#section76371145108)
8    -   [Development Example](#section994427141111)
9
10
11## Basic Concepts<a name="section11374125415814"></a>
12
13As 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.
14
15## Working Principles<a name="section189351319134418"></a>
16
17The compiler supports C++ code identification. The system calls the constructors of global objects to perform initialization operations.
18
19## Development Guidelines<a name="section166302407911"></a>
20
21### Available APIs<a name="section1881825119919"></a>
22
23**Table  1**  APIs supported by C++
24
25<a name="table14277123518139"></a>
26<table><thead align="left"><tr id="row152771935131315"><th class="cellrowborder" valign="top" width="23.792379237923793%" id="mcps1.2.4.1.1"><p id="p1127733591316"><a name="p1127733591316"></a><a name="p1127733591316"></a>Category</p>
27</th>
28<th class="cellrowborder" valign="top" width="33.02330233023302%" id="mcps1.2.4.1.2"><p id="p22771357138"><a name="p22771357138"></a><a name="p22771357138"></a>API</p>
29</th>
30<th class="cellrowborder" valign="top" width="43.18431843184319%" id="mcps1.2.4.1.3"><p id="p327714358130"><a name="p327714358130"></a><a name="p327714358130"></a>Description</p>
31</th>
32</tr>
33</thead>
34<tbody><tr id="row119525513581"><td class="cellrowborder" valign="top" width="23.792379237923793%" headers="mcps1.2.4.1.1 "><p id="p2099535514346"><a name="p2099535514346"></a><a name="p2099535514346"></a>Prerequisites for using C++ features</p>
35</td>
36<td class="cellrowborder" valign="top" width="33.02330233023302%" headers="mcps1.2.4.1.2 "><p id="p3155620345"><a name="p3155620345"></a><a name="p3155620345"></a>LOS_CppSystemInit</p>
37</td>
38<td class="cellrowborder" valign="top" width="43.18431843184319%" headers="mcps1.2.4.1.3 "><p id="p4616566343"><a name="p4616566343"></a><a name="p4616566343"></a>Initializes C++ constructors.</p>
39</td>
40</tr>
41</tbody>
42</table>
43
44### How to Develop<a name="section76371145108"></a>
45
46Before 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\_\_**.
47
48**Table  2**  Parameter description
49
50<a name="table71191652173718"></a>
51<table><thead align="left"><tr id="row1512085253715"><th class="cellrowborder" valign="top" width="42.77%" id="mcps1.2.3.1.1"><p id="p16120175233720"><a name="p16120175233720"></a><a name="p16120175233720"></a>Parameter</p>
52</th>
53<th class="cellrowborder" valign="top" width="57.230000000000004%" id="mcps1.2.3.1.2"><p id="p61205526372"><a name="p61205526372"></a><a name="p61205526372"></a>Description</p>
54</th>
55</tr>
56</thead>
57<tbody><tr id="row11120135213714"><td class="cellrowborder" valign="top" width="42.77%" headers="mcps1.2.3.1.1 "><p id="p1053212673917"><a name="p1053212673917"></a><a name="p1053212673917"></a>__init_array_start__</p>
58</td>
59<td class="cellrowborder" valign="top" width="57.230000000000004%" headers="mcps1.2.3.1.2 "><p id="p2208154219392"><a name="p2208154219392"></a><a name="p2208154219392"></a>Start of the <strong id="b13329113893818"><a name="b13329113893818"></a><a name="b13329113893818"></a>init_array</strong> section</p>
60</td>
61</tr>
62<tr id="row1591908143918"><td class="cellrowborder" valign="top" width="42.77%" headers="mcps1.2.3.1.1 "><p id="p491968193914"><a name="p491968193914"></a><a name="p491968193914"></a>__init_array_end__</p>
63</td>
64<td class="cellrowborder" valign="top" width="57.230000000000004%" headers="mcps1.2.3.1.2 "><p id="p6919189393"><a name="p6919189393"></a><a name="p6919189393"></a>End of the <strong id="b48960753912"><a name="b48960753912"></a><a name="b48960753912"></a>init_array</strong> section</p>
65</td>
66</tr>
67</tbody>
68</table>
69
70>![](../public_sys-resources/icon-note.gif) **NOTE:**
71>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.
72
73### Development Example<a name="section994427141111"></a>
74
75```
76void app_init(void)
77{
78......
79/* Initialize C++ in the startup phase. */
80LOS_CppSystemInit((UINTPTR)&__init_array_start__, (UINTPTR)&__init_array_end__);
81/* C++ service */
82......
83}
84```
85
86