162306a36Sopenharmony_ci.. include:: ../disclaimer-zh_CN.rst
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci:Original: :ref:`Documentation/process/programming-language.rst <programming_language>`
462306a36Sopenharmony_ci:Translator: Alex Shi <alex.shi@linux.alibaba.com>
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci.. _cn_programming_language:
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci程序设计语言
962306a36Sopenharmony_ci============
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci内核是用C语言 :ref:`c-language <cn_c-language>` 编写的。更准确地说,内核通常是用 :ref:`gcc <cn_gcc>`
1262306a36Sopenharmony_ci在 ``-std=gnu11`` :ref:`gcc-c-dialect-options <cn_gcc-c-dialect-options>` 下编译的:ISO C11的 GNU 方言
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci这种方言包含对语言 :ref:`gnu-extensions <cn_gnu-extensions>` 的许多扩展,当然,它们许多都在内核中使用。
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci对于一些体系结构,有一些使用 :ref:`clang <cn_clang>` 和 :ref:`icc <cn_icc>` 编译内核
1762306a36Sopenharmony_ci的支持,尽管在编写此文档时还没有完成,仍需要第三方补丁。
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci属性
2062306a36Sopenharmony_ci----
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci在整个内核中使用的一个常见扩展是属性(attributes) :ref:`gcc-attribute-syntax <cn_gcc-attribute-syntax>`
2362306a36Sopenharmony_ci属性允许将实现定义的语义引入语言实体(如变量、函数或类型),而无需对语言进行
2462306a36Sopenharmony_ci重大的语法更改(例如添加新关键字) :ref:`n2049 <cn_n2049>`
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci在某些情况下,属性是可选的(即不支持这些属性的编译器仍然应该生成正确的代码,
2762306a36Sopenharmony_ci即使其速度较慢或执行的编译时检查/诊断次数不够)
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci内核定义了伪关键字(例如, ``pure`` ),而不是直接使用GNU属性语法(例如,
3062306a36Sopenharmony_ci``__attribute__((__pure__))`` ),以检测可以使用哪些关键字和/或缩短代码, 具体
3162306a36Sopenharmony_ci请参阅 ``include/linux/compiler_attributes.h``
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci.. _cn_c-language:
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_cic-language
3662306a36Sopenharmony_ci   http://www.open-std.org/jtc1/sc22/wg14/www/standards
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci.. _cn_gcc:
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_cigcc
4162306a36Sopenharmony_ci   https://gcc.gnu.org
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci.. _cn_clang:
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ciclang
4662306a36Sopenharmony_ci   https://clang.llvm.org
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci.. _cn_icc:
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ciicc
5162306a36Sopenharmony_ci   https://software.intel.com/en-us/c-compilers
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci.. _cn_gcc-c-dialect-options:
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_cic-dialect-options
5662306a36Sopenharmony_ci   https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci.. _cn_gnu-extensions:
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_cignu-extensions
6162306a36Sopenharmony_ci   https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci.. _cn_gcc-attribute-syntax:
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_cigcc-attribute-syntax
6662306a36Sopenharmony_ci   https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci.. _cn_n2049:
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_cin2049
7162306a36Sopenharmony_ci   http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2049.pdf
72