Page 1 of 1

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

Posted: Mon Feb 06, 2023 2:19 am
by mbratch
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?

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

Posted: Mon Feb 06, 2023 3:28 pm
by espnoob
GNU extensions? You could try to pass "-pedantic" to g++. That would prohibit extensions to the Standard.

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

Posted: Mon Feb 06, 2023 5:01 pm
by mbratch
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.