1390f915aSHu Haowen.. SPDX-License-Identifier: GPL-2.0 2390f915aSHu Haowen 3390f915aSHu Haowen.. include:: ../disclaimer-zh_TW.rst 4390f915aSHu Haowen 5390f915aSHu Haowen:Original: :ref:`Documentation/process/programming-language.rst <programming_language>` 6390f915aSHu Haowen:Translator: Alex Shi <alex.shi@linux.alibaba.com> 7*335bbdf0SHu Haowen Hu Haowen <2023002089@link.tyut.edu.cn> 8390f915aSHu Haowen 9390f915aSHu Haowen.. _tw_programming_language: 10390f915aSHu Haowen 11390f915aSHu Haowen程序設計語言 12390f915aSHu Haowen============ 13390f915aSHu Haowen 14390f915aSHu Haowen內核是用C語言 :ref:`c-language <tw_c-language>` 編寫的。更準確地說,內核通常是用 :ref:`gcc <tw_gcc>` 15e8c07082SArnd Bergmann在 ``-std=gnu11`` :ref:`gcc-c-dialect-options <tw_gcc-c-dialect-options>` 下編譯的:ISO C11的 GNU 方言 16390f915aSHu Haowen 17390f915aSHu Haowen這種方言包含對語言 :ref:`gnu-extensions <tw_gnu-extensions>` 的許多擴展,當然,它們許多都在內核中使用。 18390f915aSHu Haowen 19390f915aSHu Haowen對於一些體系結構,有一些使用 :ref:`clang <tw_clang>` 和 :ref:`icc <tw_icc>` 編譯內核 20390f915aSHu Haowen的支持,儘管在編寫此文檔時還沒有完成,仍需要第三方補丁。 21390f915aSHu Haowen 22390f915aSHu Haowen屬性 23390f915aSHu Haowen---- 24390f915aSHu Haowen 25390f915aSHu Haowen在整個內核中使用的一個常見擴展是屬性(attributes) :ref:`gcc-attribute-syntax <tw_gcc-attribute-syntax>` 26390f915aSHu Haowen屬性允許將實現定義的語義引入語言實體(如變量、函數或類型),而無需對語言進行 27390f915aSHu Haowen重大的語法更改(例如添加新關鍵字) :ref:`n2049 <tw_n2049>` 28390f915aSHu Haowen 29390f915aSHu Haowen在某些情況下,屬性是可選的(即不支持這些屬性的編譯器仍然應該生成正確的代碼, 30390f915aSHu Haowen即使其速度較慢或執行的編譯時檢查/診斷次數不夠) 31390f915aSHu Haowen 32390f915aSHu Haowen內核定義了僞關鍵字(例如, ``pure`` ),而不是直接使用GNU屬性語法(例如, 33390f915aSHu Haowen``__attribute__((__pure__))`` ),以檢測可以使用哪些關鍵字和/或縮短代碼, 具體 34390f915aSHu Haowen請參閱 ``include/linux/compiler_attributes.h`` 35390f915aSHu Haowen 36390f915aSHu Haowen.. _tw_c-language: 37390f915aSHu Haowen 38390f915aSHu Haowenc-language 39390f915aSHu Haowen http://www.open-std.org/jtc1/sc22/wg14/www/standards 40390f915aSHu Haowen 41390f915aSHu Haowen.. _tw_gcc: 42390f915aSHu Haowen 43390f915aSHu Haowengcc 44390f915aSHu Haowen https://gcc.gnu.org 45390f915aSHu Haowen 46390f915aSHu Haowen.. _tw_clang: 47390f915aSHu Haowen 48390f915aSHu Haowenclang 49390f915aSHu Haowen https://clang.llvm.org 50390f915aSHu Haowen 51390f915aSHu Haowen.. _tw_icc: 52390f915aSHu Haowen 53390f915aSHu Haowenicc 54390f915aSHu Haowen https://software.intel.com/en-us/c-compilers 55390f915aSHu Haowen 56390f915aSHu Haowen.. _tw_gcc-c-dialect-options: 57390f915aSHu Haowen 58390f915aSHu Haowenc-dialect-options 59390f915aSHu Haowen https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html 60390f915aSHu Haowen 61390f915aSHu Haowen.. _tw_gnu-extensions: 62390f915aSHu Haowen 63390f915aSHu Haowengnu-extensions 64390f915aSHu Haowen https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html 65390f915aSHu Haowen 66390f915aSHu Haowen.. _tw_gcc-attribute-syntax: 67390f915aSHu Haowen 68390f915aSHu Haowengcc-attribute-syntax 69390f915aSHu Haowen https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html 70390f915aSHu Haowen 71390f915aSHu Haowen.. _tw_n2049: 72390f915aSHu Haowen 73390f915aSHu Haowenn2049 74390f915aSHu Haowen http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2049.pdf 75390f915aSHu Haowen 76