18c2ecf20Sopenharmony_ci.. include:: ../disclaimer-zh_CN.rst
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ci:Original: :ref:`Documentation/process/programming-language.rst <programming_language>`
48c2ecf20Sopenharmony_ci:Translator: Alex Shi <alex.shi@linux.alibaba.com>
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci.. _cn_programming_language:
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci程序设计语言
98c2ecf20Sopenharmony_ci============
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci内核是用C语言 :ref:`c-language <cn_c-language>` 编写的。更准确地说,内核通常是用 :ref:`gcc <cn_gcc>`
128c2ecf20Sopenharmony_ci在 ``-std=gnu89`` :ref:`gcc-c-dialect-options <cn_gcc-c-dialect-options>` 下编译的:ISO C90的 GNU 方言(
138c2ecf20Sopenharmony_ci包括一些C99特性)
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci这种方言包含对语言 :ref:`gnu-extensions <cn_gnu-extensions>` 的许多扩展,当然,它们许多都在内核中使用。
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci对于一些体系结构,有一些使用 :ref:`clang <cn_clang>` 和 :ref:`icc <cn_icc>` 编译内核
188c2ecf20Sopenharmony_ci的支持,尽管在编写此文档时还没有完成,仍需要第三方补丁。
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci属性
218c2ecf20Sopenharmony_ci----
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci在整个内核中使用的一个常见扩展是属性(attributes) :ref:`gcc-attribute-syntax <cn_gcc-attribute-syntax>`
248c2ecf20Sopenharmony_ci属性允许将实现定义的语义引入语言实体(如变量、函数或类型),而无需对语言进行
258c2ecf20Sopenharmony_ci重大的语法更改(例如添加新关键字) :ref:`n2049 <cn_n2049>`
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci在某些情况下,属性是可选的(即不支持这些属性的编译器仍然应该生成正确的代码,
288c2ecf20Sopenharmony_ci即使其速度较慢或执行的编译时检查/诊断次数不够)
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci内核定义了伪关键字(例如, ``pure`` ),而不是直接使用GNU属性语法(例如,
318c2ecf20Sopenharmony_ci``__attribute__((__pure__))`` ),以检测可以使用哪些关键字和/或缩短代码, 具体
328c2ecf20Sopenharmony_ci请参阅 ``include/linux/compiler_attributes.h``
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci.. _cn_c-language:
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_cic-language
378c2ecf20Sopenharmony_ci   http://www.open-std.org/jtc1/sc22/wg14/www/standards
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci.. _cn_gcc:
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_cigcc
428c2ecf20Sopenharmony_ci   https://gcc.gnu.org
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci.. _cn_clang:
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ciclang
478c2ecf20Sopenharmony_ci   https://clang.llvm.org
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci.. _cn_icc:
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ciicc
528c2ecf20Sopenharmony_ci   https://software.intel.com/en-us/c-compilers
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci.. _cn_gcc-c-dialect-options:
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cic-dialect-options
578c2ecf20Sopenharmony_ci   https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci.. _cn_gnu-extensions:
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_cignu-extensions
628c2ecf20Sopenharmony_ci   https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci.. _cn_gcc-attribute-syntax:
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_cigcc-attribute-syntax
678c2ecf20Sopenharmony_ci   https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci.. _cn_n2049:
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_cin2049
728c2ecf20Sopenharmony_ci   http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2049.pdf
73