esp-idf use of std=gnu99

Xavi92
Posts: 45
Joined: Thu Mar 28, 2019 2:26 pm

esp-idf use of std=gnu99

Postby Xavi92 » Tue Mar 03, 2020 8:56 am

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?

Xavi92
Posts: 45
Joined: Thu Mar 28, 2019 2:26 pm

Re: esp-idf use of std=gnu99

Postby Xavi92 » Thu Mar 19, 2020 2:54 pm

Could anyone please provide an answer to this topic?
Thank you very much.

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: esp-idf use of std=gnu99

Postby ESP_Angus » Fri Mar 20, 2020 8:19 am

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")

Xavi92
Posts: 45
Joined: Thu Mar 28, 2019 2:26 pm

Re: esp-idf use of std=gnu99

Postby Xavi92 » Fri Mar 20, 2020 10:38 am

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

AshUK_
Posts: 3
Joined: Tue Jul 28, 2020 1:00 pm

Re: esp-idf use of std=gnu99

Postby AshUK_ » Wed Dec 02, 2020 5:24 pm

+1 for gnu17 support, the component work around, just doesn't work for us, looking forward to IDF 5.0 :D

Who is online

Users browsing this forum: Gaston1980, ok-home and 81 guests