Merge branch 'docs/update_cn_for_api-conventions' into 'master'

Docs: Update CN for /api-reference/api-conventions.rst

Closes DOC-5172

See merge request espressif/esp-idf!24017
This commit is contained in:
Wang Zi Yan
2023-06-08 16:59:34 +08:00
2 changed files with 18 additions and 4 deletions

View File

@@ -55,7 +55,7 @@ Most ESP-IDF examples use C99 `designated initializers`_ for structure initializ
/* Correct, fields .arg and .name are zero-initialized */ /* Correct, fields .arg and .name are zero-initialized */
}; };
The C++ language supports designated initializers syntax, too, but the initializers must be in the order of declaration. When using ESP-IDF APIs in C++ code, you may consider using the following pattern:: The C++ language supports designated initializer syntax, too, but the initializers must be in the order of declaration. When using ESP-IDF APIs in C++ code, you may consider using the following pattern::
/* Correct, fields .dispatch_method, .name and .skip_unhandled_events are zero-initialized */ /* Correct, fields .dispatch_method, .name and .skip_unhandled_events are zero-initialized */
const esp_timer_create_args_t my_timer_args = { const esp_timer_create_args_t my_timer_args = {
@@ -69,7 +69,7 @@ The C++ language supports designated initializers syntax, too, but the initializ
// .callback = &my_timer_callback, // .callback = &my_timer_callback,
//}; //};
For more information on designated initializers, see :ref:`Designated initializers <cplusplus_designated_initializers>`. Note that C++ language versions older than C++20 (not the default in the current version of ESP-IDF) do not support designated initializers. If you have to compile code with an older C++ standard than C++20, you may use GCC extensions to produce the following pattern:: For more information on designated initializers, see :ref:`cplusplus_designated_initializers`. Note that C++ language versions older than C++20, which are not the default in the current version of ESP-IDF, do not support designated initializers. If you have to compile code with an older C++ standard than C++20, you may use GCC extensions to produce the following pattern::
esp_timer_create_args_t my_timer_args = {}; esp_timer_create_args_t my_timer_args = {};
/* All the fields are zero-initialized */ /* All the fields are zero-initialized */

View File

@@ -55,10 +55,24 @@ ESP-IDF 由多个组件组成,组件中包含专门为 ESP 芯片编写的代
/* 正确,字段 .arg 和 .name 已初始化为零 */ /* 正确,字段 .arg 和 .name 已初始化为零 */
}; };
C++ 语言在 C++20 之前不支持指定初始化器语法,但是 GCC 编译器可以作为扩展实现部分指定初始化器功能。在 C++ 代码中使用 ESP-IDF API 时,可以考虑使用以下模式:: C++ 语言同样支持指定初始化器语法,但初始化器必须遵循声明顺序。在 C++ 代码中使用 ESP-IDF API 时,可以考虑使用以下模式::
/* 正确:.dispatch_method、.name 以及 .skip_unhandled_events 初始化为零 */
const esp_timer_create_args_t my_timer_args = {
.callback = &my_timer_callback,
.arg = &my_arg,
};
///* 错误esp_timer_create_args_t 中,.arg 在 .callback 之后声明 */
//const esp_timer_create_args_t my_timer_args = {
// .arg = &my_arg,
// .callback = &my_timer_callback,
//};
了解指定初始化器的更多信息,请参见 :ref:`cplusplus_designated_initializers`。注意C++20 之前的 C++ 语言不是当前 ESP-IDF 的默认版本,不支持指定初始化器。如需使用 C++20 之前的 C++ 标准编译代码,可以借助 GCC 扩展生成以下模式::
esp_timer_create_args_t my_timer_args = {}; esp_timer_create_args_t my_timer_args = {};
/* 所有字段初始化为零 */ /* 所有字段初始化为零 */
my_timer_args.callback = &my_timer_callback; my_timer_args.callback = &my_timer_callback;
默认初始化器 默认初始化器