docs: Provide translation for c.rst

This commit is contained in:
shenmengjing 2024-03-27 15:01:31 +08:00 committed by BOT
parent 95ab3ccf96
commit 3b76cae7e7
2 changed files with 36 additions and 5 deletions

View File

@ -3,9 +3,7 @@ C Support
:link_to_translation:`zh_CN:[中文]`
.. highlight:: cpp
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.
ESP-IDF is primarily written in C and provides C APIs. ESP-IDF uses `Newlib <https://sourceware.org/newlib/>`_ as its C Standard Library implementation (the Newlib version is specified in :component_file:`newlib/sbom.yml`). In general, all C features that are supported by the compiler (currently GCC) can be used in ESP-IDF, unless specified in :ref:`unsupported_c_features` below.
.. _c_version:
@ -33,4 +31,4 @@ The following features are not supported in ESP-IDF.
Nested Function Pointers
^^^^^^^^^^^^^^^^^^^^^^^^
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.
The **GNU dialect of ISO C17** supports `nested functions <https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html>`_. However, ESP-IDF does not support referencing nested functions as pointers. This is due to the fact that the GCC compiler generates a `trampoline <https://gcc.gnu.org/onlinedocs/gccint/Trampolines.html>`_ (i.e., small piece of executable code) on the stack when a pointer to a nested function is referenced. ESP-IDF does not permit executing code from a stack, thus use of pointers to nested functions is not supported.

View File

@ -1 +1,34 @@
.. include:: ../../en/api-guides/c.rst
C 支持
======
:link_to_translation:`en:[English]`
ESP-IDF 主要使用 C 语言编写,并提供 C 语言 API。ESP-IDF 使用 `Newlib <https://sourceware.org/newlib/>`_ 作为 C 标准函数库对实现Newlib 版本可以在 :component_file:`newlib/sbom.yml` 指定)。一般来说,除非在下面的 :ref:`unsupported_c_features` 中特别说明,当前使用的编译器(目前是 GCC支持的所有 C 语言功能在 ESP-IDF 中均可使用。
.. _c_version:
C 版本
------
**ISO C17 的 GNU 方言** (``--std=gnu17``) 是 ESP-IDF 中当前默认的 C 语言版本。
使用不同的语言标准编译某个组件的源代码,请在组件的 ``CMakeLists.txt`` 文件中设置所需的编译器标志:
.. code-block:: cmake
idf_component_register( ... )
target_compile_options(${COMPONENT_LIB} PRIVATE -std=gnu11)
如果组件的公共头文件也需要使用相同的语言标准编译,请将标志 ``PRIVATE`` 替换为 ``PUBLIC``
.. _unsupported_c_features:
不支持的 C 功能
---------------
ESP-IDF 不支持以下功能。
嵌套函数的指针
^^^^^^^^^^^^^^
**ISO C17 的 GNU 方言** 支持 `嵌套函数 <https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html>`_,但 ESP-IDF 不支持将嵌套函数引用为指针。这是因为 GCC 编译器在引用嵌套函数的指针时,会在栈上生成一个 `跳板 <https://gcc.gnu.org/onlinedocs/gccint/Trampolines.html>`_ 一小段可执行代码ESP-IDF 不允许从栈执行代码,因此不支持使用指向嵌套函数的指针。