c.rst 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. C Support
  2. ===========
  3. :link_to_translation:`zh_CN:[中文]`
  4. .. highlight:: cpp
  5. ESP-IDF is primarily written in C and provides C APIs. `Newlib <https://sourceware.org/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.
  6. .. _c_version:
  7. C Version
  8. ---------
  9. **GNU dialect of ISO C17** (``--std=gnu17``) is the current default C version in ESP-IDF.
  10. 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:
  11. .. code-block:: cmake
  12. idf_component_register( ... )
  13. target_compile_options(${COMPONENT_LIB} PRIVATE -std=gnu11)
  14. If the public header files of the component also need to be compiled with the same language standard, replace the flag ``PRIVATE`` with ``PUBLIC``.
  15. .. _unsupported_c_features:
  16. Unsupported C Features
  17. ----------------------
  18. The following features are not supported in ESP-IDF.
  19. Nested Function Pointers
  20. ^^^^^^^^^^^^^^^^^^^^^^^^
  21. The **GNU dialect of ISO C17** supports `nested functions <https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html>`_. 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.