mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-31 22:24:28 +00:00
Merge branch 'contrib/github_pr_11025_v5.1' into 'release/v5.1'
Enable support for C++23 in esp-idf (GitHub PR) (v5.1) See merge request espressif/esp-idf!23421
This commit is contained in:
@@ -54,7 +54,21 @@ Most ESP-IDF examples use C99 `designated initializers`_ for structure initializ
|
||||
/* Correct, fields .arg and .name are zero-initialized */
|
||||
};
|
||||
|
||||
C++ language doesn't support the designated initializers syntax until C++20, however GCC compiler partially supports it as an extension. When using ESP-IDF APIs in C++ code, you may consider using the following pattern::
|
||||
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::
|
||||
|
||||
/* Correct, fields .dispatch_method, .name and .skip_unhandled_events are zero-initialized */
|
||||
const esp_timer_create_args_t my_timer_args = {
|
||||
.callback = &my_timer_callback,
|
||||
.arg = &my_arg,
|
||||
};
|
||||
|
||||
///* Incorrect, .arg is declared after .callback in esp_timer_create_args_t */
|
||||
//const esp_timer_create_args_t my_timer_args = {
|
||||
// .arg = &my_arg,
|
||||
// .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::
|
||||
|
||||
esp_timer_create_args_t my_timer_args = {};
|
||||
/* All the fields are zero-initialized */
|
||||
|
Reference in New Issue
Block a user