18c2ecf20Sopenharmony_ci.. _programming_language:
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ciProgramming Language
48c2ecf20Sopenharmony_ci====================
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ciThe kernel is written in the C programming language [c-language]_.
78c2ecf20Sopenharmony_ciMore precisely, the kernel is typically compiled with ``gcc`` [gcc]_
88c2ecf20Sopenharmony_ciunder ``-std=gnu89`` [gcc-c-dialect-options]_: the GNU dialect of ISO C90
98c2ecf20Sopenharmony_ci(including some C99 features). ``clang`` [clang]_ is also supported, see
108c2ecf20Sopenharmony_cidocs on :ref:`Building Linux with Clang/LLVM <kbuild_llvm>`.
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ciThis dialect contains many extensions to the language [gnu-extensions]_,
138c2ecf20Sopenharmony_ciand many of them are used within the kernel as a matter of course.
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ciThere is some support for compiling the kernel with ``icc`` [icc]_ for several
168c2ecf20Sopenharmony_ciof the architectures, although at the time of writing it is not completed,
178c2ecf20Sopenharmony_cirequiring third-party patches.
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ciAttributes
208c2ecf20Sopenharmony_ci----------
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ciOne of the common extensions used throughout the kernel are attributes
238c2ecf20Sopenharmony_ci[gcc-attribute-syntax]_. Attributes allow to introduce
248c2ecf20Sopenharmony_ciimplementation-defined semantics to language entities (like variables,
258c2ecf20Sopenharmony_cifunctions or types) without having to make significant syntactic changes
268c2ecf20Sopenharmony_cito the language (e.g. adding a new keyword) [n2049]_.
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ciIn some cases, attributes are optional (i.e. a compiler not supporting them
298c2ecf20Sopenharmony_cishould still produce proper code, even if it is slower or does not perform
308c2ecf20Sopenharmony_cias many compile-time checks/diagnostics).
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ciThe kernel defines pseudo-keywords (e.g. ``__pure``) instead of using
338c2ecf20Sopenharmony_cidirectly the GNU attribute syntax (e.g. ``__attribute__((__pure__))``)
348c2ecf20Sopenharmony_ciin order to feature detect which ones can be used and/or to shorten the code.
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ciPlease refer to ``include/linux/compiler_attributes.h`` for more information.
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci.. [c-language] http://www.open-std.org/jtc1/sc22/wg14/www/standards
398c2ecf20Sopenharmony_ci.. [gcc] https://gcc.gnu.org
408c2ecf20Sopenharmony_ci.. [clang] https://clang.llvm.org
418c2ecf20Sopenharmony_ci.. [icc] https://software.intel.com/en-us/c-compilers
428c2ecf20Sopenharmony_ci.. [gcc-c-dialect-options] https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html
438c2ecf20Sopenharmony_ci.. [gnu-extensions] https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html
448c2ecf20Sopenharmony_ci.. [gcc-attribute-syntax] https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html
458c2ecf20Sopenharmony_ci.. [n2049] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2049.pdf
468c2ecf20Sopenharmony_ci
47