diff --git a/docs/en/api-guides/c.rst b/docs/en/api-guides/c.rst new file mode 100644 index 0000000000..50f50e52af --- /dev/null +++ b/docs/en/api-guides/c.rst @@ -0,0 +1,36 @@ +C Support +=========== + +:link_to_translation:`zh_CN:[δΈ­ζ–‡]` + +.. highlight:: cpp + +ESP-IDF is primarily written in C and provides C APIs. `Newlib `_ is used as standard C library (the Newlib version can be found in :component_file:`newlib/sbom.yml`). In general, all C features supported by the compiler, currently GCC, should be available in ESP-IDF, unless specified in :ref:`unsupported_c_features` below. + +.. _c_version: + +C Version +--------- + +**GNU dialect of ISO C17** (``--std=gnu17``) is the current default C version in ESP-IDF. + +To compile the source code of a certain component using a different language standard, set the desired compiler flag in the component's ``CMakeLists.txt`` file: + +.. code-block:: cmake + + idf_component_register( ... ) + target_compile_options(${COMPONENT_LIB} PRIVATE -std=gnu11) + +If the public header files of the component also need to be compiled with the same language standard, replace the flag ``PRIVATE`` with ``PUBLIC``. + +.. _unsupported_c_features: + +Unsupported C Features +---------------------- + +The following features are not supported in ESP-IDF. + +Nested Function Pointers +^^^^^^^^^^^^^^^^^^^^^^^^ + +The **GNU dialect of ISO C17** supports `nested functions `_. However, they do not work in ESP-IDF when referenced as function pointer because the compiler generates a trampoline on the stack, while the stack is not executable in ESP-IDF. Hence, do not use function pointers to nested functions. diff --git a/docs/en/api-guides/index.rst b/docs/en/api-guides/index.rst index 19990f593f..0f2afc32c2 100644 --- a/docs/en/api-guides/index.rst +++ b/docs/en/api-guides/index.rst @@ -12,8 +12,9 @@ API Guides bootloader build-system :SOC_SUPPORT_COEXISTENCE: coexist - core_dump + c cplusplus + core_dump current-consumption-measurement-modules :SOC_RTC_MEM_SUPPORTED: deep-sleep-stub :SOC_USB_OTG_SUPPORTED: dfu diff --git a/docs/zh_CN/api-guides/c.rst b/docs/zh_CN/api-guides/c.rst new file mode 100644 index 0000000000..60ba584208 --- /dev/null +++ b/docs/zh_CN/api-guides/c.rst @@ -0,0 +1 @@ +.. include:: ../../en/api-guides/c.rst diff --git a/docs/zh_CN/api-guides/index.rst b/docs/zh_CN/api-guides/index.rst index b692ece7b2..f4ce0b5a1e 100644 --- a/docs/zh_CN/api-guides/index.rst +++ b/docs/zh_CN/api-guides/index.rst @@ -12,8 +12,9 @@ API ζŒ‡ε— bootloader build-system :SOC_SUPPORT_COEXISTENCE: coexist - core_dump + c cplusplus + core_dump current-consumption-measurement-modules :SOC_RTC_MEM_SUPPORTED: deep-sleep-stub :SOC_USB_OTG_SUPPORTED: dfu diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake index b2dc61c8eb..d86758cd15 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -129,7 +129,7 @@ function(__build_set_lang_version) if(NOT IDF_TARGET STREQUAL "linux") # Building for chip targets: we use a known version of the toolchain. # Use latest supported versions. - # Please update docs/en/api-guides/cplusplus.rst and + # Please update docs/en/api-guides/c.rst, docs/en/api-guides/cplusplus.rst and # tools/test_apps/system/cxx_build_test/main/test_cxx_standard.cpp when changing this. set(c_std gnu17) set(cxx_std gnu++2b)