C (programming language): Difference between revisions

[accepted revision][accepted revision]
Content deleted Content added
Surely a peer reviewed paper should be a good enough source
Tag: Reverted
Undid revision 1308647745 by Kbrose (talk) - per WP:BRD, perhaps the next change to this text should be after some consensus on the talk page.
 
(9 intermediate revisions by 4 users not shown)
Line 72:
* Minimized functionality in the core language while relatively complex functionality such as [[Input/output|I/O]], string manipulation, and mathematical functions supported via standard library functions
* Resulting compiled code has relatively straightforward needs on the underlying platform; making it desirable for operating and [[embedded system|embedded]] systems
* Implementations tend to be much more efficient than other popular languages. For example, inIn the paper named "Ranking programming languages by energy efficiency", researchers found typicallycertain typically-written Python benchmarks to use 75.88 times more electricity on average than the corresponding C benchmarks, while taking an average of 71.9 times more time to complete than the C benchmarks. On average, the Python benchmarks had a peak RAM usage that was 2.39 times more than the C benchmarks.<ref>{{cite web|url=https://nyuscholars.nyu.edu/en/publications/ranking-programming-languages-by-energy-efficiency|title=Ranking programming languages by energy efficiency}}</ref><ref>{{cite web|url=https://www.iro.umontreal.ca/~mignotte/IFT2425/Documents/RankingProgrammingLanguagesByEnergyEfficiency.pdf|title=Ranking programming languages by energy efficiency}}</ref> The paper has been published in Science of Computer Programming, and it has undergone peer review. <ref>{{cite web|url=https://www.sciencedirect.com/science/article/pii/S0167642321000022|title=Ranking programming languages by energy efficiency}}</ref>
{{Div col end}}
 
Line 530:
 
== Uses ==
C has also been widely used to implement [[End-user (computer science)|end-user]] and system-level applications.<ref>{{Cite web |title=After All These Years, the World is Still Powered by C Programming |first1=Daniel |last1=Munoz |url=https://www.toptal.com/c/after-all-these-years-the-world-is-still-powered-by-c-programming |access-date=November 17, 2023 |website=Toptal Engineering Blog |language=en}}</ref> However, such applications can also be written in newer, higher-level languages.
 
=== Rationale for use in systems programming ===
[[File:The C Programming Language.png|thumb|Some software written in C]]
Line 545 ⟶ 547:
* C and its [[calling convention]]s and linker structures are commonly used in conjunction with other high-level languages, with calls both to C and from C supported – it interoperates well with other high-level code.
* C has a mature and broad ecosystem, including libraries, frameworks, open source compilers, debuggers and utilities, and is the de facto standard. It is likely the drivers already exist in C, or that there is a similar CPU architecture as a back-end of a C compiler, so there is reduced incentive to choose another language.
 
===Used for computationally-intensive libraries===
C enables programmers to create efficient implementations of algorithms and data structures, because the layer of abstraction from hardware is thin, and its overhead is low, an important criterion for computationally intensive programs. For example, the [[GNU Multiple Precision Arithmetic Library]], the [[GNU Scientific Library]], [[Mathematica]], and [[MATLAB]] are completely or partially written in C. Many languages support calling library functions in C, for example, the [[Python (programming language)|Python]]-based framework [[NumPy]] uses C for the high-performance and hardware-interacting aspects.
 
===Games===
Computer games are often built from a combination of languages. C has featured significantly, especially for those games attempting to obtain best performance from computer platforms. Examples include Doom from 1993.<ref>{{cite web |title=Development of Doom |url=https://doomwiki.org/wiki/Development_of_Doom |website=DoomWiki.org |access-date=2025-03-02 |language=en |date=2 March 2025}}</ref>
 
===Web servers===
===C as an intermediate language===
The two most popular [[web server]]s, [[Apache HTTP Server]] and [[Nginx]], are both written in C. These web servers interact with the operating system, listen on TCP ports for HTTP requests, and then serve up static web content, or cause the execution of other languages handling to 'render' content such as [[PHP]], which is itself primarily written in C. C's close-to-the-metal approach allows for the construction of these high-performance software systems.
C is sometimes used as an [[intermediate language]] by implementations of other languages. This approach may be used for portability or convenience; by using C as an intermediate language, additional machine-specific code generators are not necessary. C has some features, such as line-number preprocessor directives and optional superfluous commas at the end of initializer lists, that support compilation of generated code. However, some of C's shortcomings have prompted the development of other [[C-based languages]] specifically designed for use as intermediate languages, such as [[C--]]. Also, contemporary major compilers [[GNU Compiler Collection|GCC]] and [[LLVM]] both feature an [[intermediate representation]] that is not C, and those compilers support front ends for many languages including C.
 
===Other languages written in C===
A consequence of C's wide availability and efficiency is that [[compiler]]s, libraries and [[Interpreter (computing)|interpreters]] of other programming languages are often implemented in C.<ref>{{Cite web |date=November 13, 2018 |title=C – the mother of all languages |url=https://ict.iitk.ac.in/c-the-mother-of-all-languages/ |access-date=October 11, 2022 |website=ICT Academy at IITK |language=en-US |archive-date=May 31, 2021 |archive-url=https://web.archive.org/web/20210531161841/https://ict.iitk.ac.in/c-the-mother-of-all-languages/ |url-status=dead }}</ref> For example, the [[reference implementation]]s of [[Python (programming language)|Python]],<ref>{{Cite web |title=1. Extending Python with C or C++ |website=Python 3.10.7 documentation |url=https://docs.python.org/3/extending/extending.html |access-date=October 11, 2022 |archive-date=November 5, 2012 |archive-url=https://web.archive.org/web/20121105232707/https://docs.python.org/3/extending/extending.html |url-status=live }}</ref> [[Perl]],<ref>{{Cite web |title=An overview of the Perl 5 engine |url=https://opensource.com/article/18/1/perl-5-engine |access-date=October 11, 2022 |website=Opensource.com |first1=Michael |last1=Conrad |date=January 22, 2018 |language=en |archive-date=May 26, 2022 |archive-url=https://web.archive.org/web/20220526105419/https://opensource.com/article/18/1/perl-5-engine |url-status=live }}</ref> [[Ruby (programming language)|Ruby]],<ref>{{Cite web |title=To Ruby From C and C++ |url=https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ |access-date=October 11, 2022 |website=Ruby Programming Language |archive-date=August 12, 2013 |archive-url=https://web.archive.org/web/20130812003928/https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ |url-status=live }}</ref> and [[PHP]]<ref>{{Cite web |date=August 3, 2022 |title=What is PHP? How to Write Your First PHP Program |url=https://www.freecodecamp.org/news/what-is-php-write-your-first-php-program/ |access-date=October 11, 2022 |website=freeCodeCamp |first1=Michael |last1=Para |language=en |archive-date=August 4, 2022 |archive-url=https://web.archive.org/web/20220804050401/https://www.freecodecamp.org/news/what-is-php-write-your-first-php-program/ |url-status=live }}</ref> are written in C.
 
===Once used for webWeb development===
Historically, C was sometimes used for [[web development]] using the [[Common Gateway Interface]] (CGI) as a "gateway" for information between the web application, the server, and the browser.<ref name="Dobbs 1995">{{cite book |title=Dr. Dobb's Sourcebook |publisher=Miller Freeman, Inc. |date=November–December 1995 |___location=U.S.}}</ref> C may have been chosen over [[interpreted language]]s because of its speed, stability, and near-universal availability.<ref name="linuxjournal 2005">{{cite web |url=http://www.linuxjournal.com/article/6863 |publisher=linuxjournal.com |title=Using C for CGI Programming |access-date=January 4, 2010 |date=March 1, 2005 |archive-date=February 13, 2010 |archive-url=https://web.archive.org/web/20100213075858/http://www.linuxjournal.com/article/6863 |url-status=live }}</ref> It is no longer common practice for web development to be done in C,<ref>{{cite web |last1=Perkins |first1=Luc |title=Web development in C: crazy? Or crazy like a fox? |url=https://medium.com/@lucperkins/web-development-in-c-crazy-or-crazy-like-a-fox-ff723209f8f5 |website=Medium |language=en |date=September 17, 2013 |access-date=April 8, 2022 |archive-date=October 4, 2014 |archive-url=https://web.archive.org/web/20141004135317/https://medium.com/@lucperkins/web-development-in-c-crazy-or-crazy-like-a-fox-ff723209f8f5 |url-status=live }}</ref> and many other [[web development#Server-side languages|web development languages]] are popular. Applications where C-based web development continues include the [[HTTP]] configuration pages on [[Router (computing)|routers]], [[IoT]] devices and similar, although even here some projects have parts in higher-level languages e.g. the use of [[Lua (programming language)|Lua]] within [[OpenWRT]].
 
===C as an intermediate language===
===Web servers===
C is sometimes used as an [[intermediate language]] by implementations of other languages. This approach may be used for portability or convenience; by using C as an intermediate language, additional machine-specific code generators are not necessary. C has some features, such as line-number preprocessor directives and optional superfluous commas at the end of initializer lists, that support compilation of generated code. However, some of C's shortcomings have prompted the development of other [[C-based languages]] specifically designed for use as intermediate languages, such as [[C--]]. Also, contemporary major compilers [[GNU Compiler Collection|GCC]] and [[LLVM]] both feature an [[intermediate representation]] that is not C, and those compilers support front ends for many languages including C.
The two most popular [[web server]]s, [[Apache HTTP Server]] and [[Nginx]], are both written in C. These web servers interact with the operating system, listen on TCP ports for HTTP requests, and then serve up static web content, or cause the execution of other languages handling to 'render' content such as [[PHP]], which is itself primarily written in C. C's close-to-the-metal approach allows for the construction of these high-performance software systems.
 
===Used for computationallyComputationally-intensive libraries===
===End-user applications===
C enables programmers to create efficient implementations of algorithms and data structures, because the layer of abstraction from hardware is thin, and its overhead is low, an important criterion for computationally intensive programs. For example, the [[GNU Multiple Precision Arithmetic Library]], the [[GNU Scientific Library]], [[Mathematica]], and [[MATLAB]] are completely or partially written in C. Many languages support calling library functions in C, for example, the [[Python (programming language)|Python]]-based framework [[NumPy]] uses C for the high-performance and hardware-interacting aspects.
C has also been widely used to implement [[End-user (computer science)|end-user]] applications.<ref>{{Cite web |title=After All These Years, the World is Still Powered by C Programming |first1=Daniel |last1=Munoz |url=https://www.toptal.com/c/after-all-these-years-the-world-is-still-powered-by-c-programming |access-date=November 17, 2023 |website=Toptal Engineering Blog |language=en}}</ref> However, such applications can also be written in newer, higher-level languages.
 
===Other languages are written in C===
A consequence of C's wide availability and efficiency is that [[compiler]]s, libraries and [[Interpreter (computing)|interpreters]] of other programming languages are often implemented in C.<ref>{{Cite web |date=November 13, 2018 |title=C – the mother of all languages |url=https://ict.iitk.ac.in/c-the-mother-of-all-languages/ |access-date=October 11, 2022 |website=ICT Academy at IITK |language=en-US |archive-date=May 31, 2021 |archive-url=https://web.archive.org/web/20210531161841/https://ict.iitk.ac.in/c-the-mother-of-all-languages/ |url-status=dead }}</ref> For example, the [[reference implementation]]s of [[Python (programming language)|Python]],<ref>{{Cite web |title=1. Extending Python with C or C++ |website=Python 3.10.7 documentation |url=https://docs.python.org/3/extending/extending.html |access-date=October 11, 2022 |archive-date=November 5, 2012 |archive-url=https://web.archive.org/web/20121105232707/https://docs.python.org/3/extending/extending.html |url-status=live }}</ref> [[Perl]],<ref>{{Cite web |title=An overview of the Perl 5 engine |url=https://opensource.com/article/18/1/perl-5-engine |access-date=October 11, 2022 |website=Opensource.com |first1=Michael |last1=Conrad |date=January 22, 2018 |language=en |archive-date=May 26, 2022 |archive-url=https://web.archive.org/web/20220526105419/https://opensource.com/article/18/1/perl-5-engine |url-status=live }}</ref> [[Ruby (programming language)|Ruby]],<ref>{{Cite web |title=To Ruby From C and C++ |url=https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ |access-date=October 11, 2022 |website=Ruby Programming Language |archive-date=August 12, 2013 |archive-url=https://web.archive.org/web/20130812003928/https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ |url-status=live }}</ref> and [[PHP]]<ref>{{Cite web |date=August 3, 2022 |title=What is PHP? How to Write Your First PHP Program |url=https://www.freecodecamp.org/news/what-is-php-write-your-first-php-program/ |access-date=October 11, 2022 |website=freeCodeCamp |first1=Michael |last1=Para |language=en |archive-date=August 4, 2022 |archive-url=https://web.archive.org/web/20220804050401/https://www.freecodecamp.org/news/what-is-php-write-your-first-php-program/ |url-status=live }}</ref> are written in C.
 
==Limitations==