The C++17 version of the Xtensa C++ compiler supports designated initializers?

User avatar
mbratch
Posts: 298
Joined: Fri Jun 11, 2021 1:51 pm

The C++17 version of the Xtensa C++ compiler supports designated initializers?

Postby mbratch » Mon Feb 06, 2023 2:19 am

I was just puzzling over something...

My ESP-IDF v5.0 application is written in C++. In my main CMakeList.txt I have the following settings:

Code: Select all

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
I added the following statement in my `main.cpp` to check:

Code: Select all

std::cout << __cplusplus << "\n";
The output I received is:

Code: Select all

201703
This is all as I would expect. However, I am able to use designated initializers for regular C structures in this code. For example:

Code: Select all

    // Initialize PWM

    ledc_timer_config_t ledcTimer = {
            .speed_mode = _ledcMode,            // timer mode
            .duty_resolution = _ledcResolution, // resolution of PWM duty
            .timer_num = LEDC_TIMER_0,          // timer index
            .freq_hz = 5000,                    // frequency of PWM signal
            .clk_cfg = LEDC_AUTO_CLK            // Auto select the source clock
    };

    ledc_timer_config(&ledcTimer);
Using "standard" C++17 I would have expected this to generate a compiler error since the documentation I've read says that designated initializers aren't supported until C++20.

Is the Xtensa C++ compiler different in this regard? If so, is there any documentation regarding in what ways it deviates from the standard?

espnoob
Posts: 12
Joined: Mon Oct 31, 2022 3:22 pm

Re: The C++17 version of the Xtensa C++ compiler supports designated initializers?

Postby espnoob » Mon Feb 06, 2023 3:28 pm

GNU extensions? You could try to pass "-pedantic" to g++. That would prohibit extensions to the Standard.

User avatar
mbratch
Posts: 298
Joined: Fri Jun 11, 2021 1:51 pm

Re: The C++17 version of the Xtensa C++ compiler supports designated initializers?

Postby mbratch » Mon Feb 06, 2023 5:01 pm

espnoob wrote:
Mon Feb 06, 2023 3:28 pm
GNU extensions? You could try to pass "-pedantic" to g++. That would prohibit extensions to the Standard.
Ah, ok, Gnu extensions. That makes sense. Thanks for that. I'm not interested in inhibiting the extensions. I was just wanting to understand on what basis the C++17 compiler was allowing a C++20 construct.

Who is online

Users browsing this forum: Bing [Bot], FrankJensen, ttijass and 121 guests