Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
C (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Uses == === Rationale for use in systems programming === [[File:The C Programming Language.png|thumb|Some software written in C]] C is widely used for [[systems programming]] in implementing [[operating system]]s and [[embedded system]] applications.<ref name="Zh3CW">{{Cite book|title=Programming and problem solving with C++ |edition=6th |last1=Dale |first1=Nell B. |last2=Weems |first2=Chip |year=2014 |location=Burlington, Massachusetts |publisher=Jones & Bartlett Learning |isbn=978-1449694289 |oclc=894992484}}</ref> This is for several reasons: * The C language permits platform hardware and memory to be accessed with pointers and [[type punning]], so system-specific features (e.g. [[Control/Status Register]]s, [[Memory-mapped I/O|I/O registers]]) can be configured and used with code written in C β it allows fullest control of the platform it is running on. * The code generated after compilation does not demand many [[runtime system|system features]], and can be invoked from some boot code in a straightforward manner β it is simple to execute. * The C language statements and expressions typically map well on to sequences of instructions for the target processor, and consequently there is a low [[Run time (program lifecycle phase)|run-time]] demand on system resources β it is fast to execute. * With its rich set of operators, the C language can use many of the features of target CPUs. Where a particular CPU has more esoteric instructions, a language variant can be constructed with perhaps [[intrinsic function]]s to exploit those instructions β it can use practically all the target CPU's features. * The language makes it easy to overlay structures onto blocks of binary data, allowing the data to be comprehended, navigated and modified β it can write data structures, even file systems. * The language supports a rich set of operators, including bit manipulation, for integer arithmetic and logic, and perhaps different sizes of floating point numbers β it can process appropriately-structured data effectively. * C is a fairly small language, with only a handful of statements, and without too many features that generate extensive target code β it is comprehensible. * C has direct control over memory allocation and deallocation, which gives reasonable efficiency and predictable timing to memory-handling operations, without any concerns for sporadic ''[[stop-the-world]]'' garbage collection events β it has predictable performance. * C permits the use and implementation of different [[C dynamic memory allocation|memory allocation]] schemes, including a typical {{code |lang=c |malloc}} and {{code |lang=c |free}}; a more sophisticated mechanism with [[Region-based memory management|''arenas'']]; or a version for an [[OS kernel]] that may suit [[Direct memory access|DMA]], use within [[interrupt handler]]s, or integrated with the [[virtual memory]] system. * Depending on the linker and environment, C code can also call libraries written in [[assembly language]], and may be called from assembly language β it interoperates well with other lower-level code. * 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 very 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> ===C as an intermediate language=== 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 web 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]]. ===Web servers=== 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. ===End-user applications=== 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.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)