更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
los_cppsupport.c
浏览该文件的文档.
1/*
2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this list of
9 * conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 * of conditions and the following disclaimer in the documentation and/or other materials
13 * provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16 * to endorse or promote products derived from this software without specific prior written
17 * permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#include "los_cppsupport.h"
33#include "los_printf.h"
34/**
35 * @brief @file los_cppsupport.c
36 * @verbatim
37 基本概念
38 C++作为目前使用最广泛的编程语言之一,支持类、封装、重载等特性,是在C语言基础上
39 开发的一种面向对象的编程语言。
40
41 运作机制
42 STL(Standard Template Library)标准模板库,是一些“容器”的集合,也是算法和其他
43 一些组件的集合。其目的是标准化组件,使用标准化组件后可以不用重新开发,直接使用现成的组件。
44
45 开发流程
46 通过make menuconfig使能C++支持。
47 使用C++特性之前,需要调用函数LOS_CppSystemInit,初始化C++构造函数。
48 C函数与C++函数混合调用。在C++中调用C程序的函数,代码需加入C++包含的宏:
49 #ifdef __cplusplus
50 #if __cplusplus
51 extern "C" {
52 #endif /* __cplusplus * /
53 #endif /* __cplusplus * /
54 /* code * /
55 ...
56 #ifdef __cplusplus
57 #if __cplusplus
58 }
59 #endif /* __cplusplus * /
60 #endif /* __cplusplus * /
61 * @endverbatim
62 */
63
64typedef VOID (*InitFunc)(VOID);
65
66/**
67 * @brief 使用C++特性的前置条件 初始化C++构造函数
68 * @param initArrayStart init_array段的起始地址
69 * @param initArrayEnd init_array段的结束地址
70 * @param flag 标记调用C++特性时的场景
71 * @return LITE_OS_SEC_TEXT_MINOR
72 */
73LITE_OS_SEC_TEXT_MINOR INT32 LOS_CppSystemInit(UINTPTR initArrayStart, UINTPTR initArrayEnd, INT32 flag)
74{
75 UINTPTR *start = (UINTPTR *)initArrayStart;
76 InitFunc initFunc = NULL;
77
78 for (; start != (UINTPTR *)initArrayEnd; ++start) {
79 initFunc = (InitFunc)(*start);
80 initFunc();
81 }
82
83 return 0;
84}
85
LITE_OS_SEC_TEXT_MINOR INT32 LOS_CppSystemInit(UINTPTR initArrayStart, UINTPTR initArrayEnd, INT32 flag)
使用C++特性的前置条件 初始化C++构造函数
VOID(* InitFunc)(VOID)
signed int INT32
Definition: los_typedef.h:60
unsigned long UINTPTR
Definition: los_typedef.h:68