Page 1 of 1

esp-idf use of std=gnu99

Posted: Tue Mar 03, 2020 8:56 am
by Xavi92
Hello,

Is there any technical reason why esp-idf v4.0 and release/v4.1 are still using std=gnu99 over newer versions of the language (such as gnu11)? The following preprocessor-time error triggers on std=gnu99:

Code: Select all

#define STR(x) #x
#define _STR(x) STR(x)

#if __STDC_VERSION__ >= 201112L
/* C11-compliant code here */
#else
#error C11 not supported
#pragma message "Supported C standard: " _STR(__STDC_VERSION__)
#endif

Code: Select all

#error C11 not supported
note: #pragma message: Supported C standard: 199901L
I am preparing a header file to be shared among various projects and microcontrollers which uses _Generic, so it requires C11 support. Surprisingly though, gnu99 supports _Generic even if __STDC_VERSION__ < 201112L, but that is not a safe assumption under other compilers. For the time being, I am skipping the C version check as long as CONFIG_IDF_TARGET_ESP32 or CONFIG_IDF_TARGET_ESP32S2BETA are defined, but that does not sound reasonable.

Is there any real reason not to migrate to std=gnu11?

Re: esp-idf use of std=gnu99

Posted: Thu Mar 19, 2020 2:54 pm
by Xavi92
Could anyone please provide an answer to this topic?
Thank you very much.

Re: esp-idf use of std=gnu99

Posted: Fri Mar 20, 2020 8:19 am
by ESP_Angus
Hi Xavi,

We will look at migrating to gnu11 in a future version. We may not do this until IDF v5.0 to avoid any possibility of breaking or changing code that currently compiles with gnu99.

For now, it's possible for an ESP-IDF component to specify that its source files should be compiled with any valid -std= argument. The only limitation is that the component's public header files may be included from another source file which is compiled against a different C standard.

To apply a custom -std= argument when compiling a single file in a component, do it like this (GNU Make then CMake):
https://github.com/espressif/esp-idf/bl ... ent.mk#L10
https://github.com/espressif/esp-idf/bl ... ts.txt#L50

To apply the argument to the entire component, for GNU Make place "CFLAGS += -std=gnu11" anywhere in the component.mk file.

For CMake, place a single line like this after the idf_component_register line in the component CMakeLists.txt file:

Code: Select all

target_compile_options(${COMPONENT_LIB} PRIVATE "-std=gnu11")

Re: esp-idf use of std=gnu99

Posted: Fri Mar 20, 2020 10:38 am
by Xavi92
Hi Angus,

Thank you very much for your answer and the examples provided. Then I guess std=gnu99 is there for historical reasons, right?

Best regards,
Xavi

Re: esp-idf use of std=gnu99

Posted: Wed Dec 02, 2020 5:24 pm
by AshUK_
+1 for gnu17 support, the component work around, just doesn't work for us, looking forward to IDF 5.0 :D