User:APenguinThatIsSilly/sandbox
Uses
[edit]Rationale for use in systems programming
[edit]![](http://up.wiki.x.io/wikipedia/commons/thumb/1/10/The_C_Programming_Language.png/220px-The_C_Programming_Language.png)
C is widely used for systems programming in implementing operating systems and embedded system applications.[1] 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 Registers, 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 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 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 functions 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 memory allocation schemes, including a typical
malloc
andfree
; a more sophisticated mechanism with arenas; or a version for an OS kernel that may suit DMA, use within interrupt handlers, 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 conventions 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.
Uses
[edit]Systems programming
[edit]![](http://up.wiki.x.io/wikipedia/commons/thumb/1/10/The_C_Programming_Language.png/220px-The_C_Programming_Language.png)
C is widely used for systems programming in implementing operating systems and embedded system applications.[1], especially in kernals such as in Linux, the Windows kernel, and the XNU kernel on macOS. It is very low-level, allowing easy manipulation of hardware, especially memory. The language also maps well to the assembly it compiles to, being somewhat easy to predict what it will do and use. C is a mature programming language, with many tools to help users of it, including optimizing compilers like GCC, valgrind, make, and cmake.[2]
Used for computationally-intensive libraries
[edit]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-based framework NumPy uses C for the high-performance and hardware-interacting aspects.
Computationally-intensive libraries
[edit]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-based framework NumPy uses C for the high-performance and hardware-interacting aspects.
C as an intermediate language
[edit]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 GCC and LLVM both feature an intermediate representation that is not C, and those compilers support front ends for many languages including C.
Intermediate language
[edit]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 GCC and LLVM both feature an intermediate representation that is not C, and those compilers support front ends for many languages including C.
Parsers
[edit]A consequence of C's wide availability and efficiency is that compilers, libraries and interpreters of other programming languages are often implemented in C.[3] For example, the reference implementations of Python,[4] Perl,[5] Ruby,[6] and PHP[7] are written in C.
Web development
[edit]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.[8] C may have been chosen over interpreted languages because of its speed, stability, and near-universal availability.[9] It is no longer common practice for web development to be done in C,[10] and many other web development languages are popular. Applications where C-based web development continues include the HTTP configuration pages on routers, IoT devices and similar, although even here some projects have parts in higher-level languages e.g. the use of Lua within OpenWRT.
Some web servers are written in C. The two most popular web servers, Apache HTTP Server and Nginx, are both written in the language. 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
[edit]C has also been widely used to implement end-user applications.[11] However, such applications can also be written in newer, higher-level languages.
- ^ a b Dale, Nell B.; Weems, Chip (2014). Programming and problem solving with C++ (6th ed.). Burlington, Massachusetts: Jones & Bartlett Learning. ISBN 978-1449694289. OCLC 894992484.
- ^ "C programming tools". Brown CS. Retrieved 17 January 2025.
- ^ "C – the mother of all languages". ICT Academy at IITK. November 13, 2018. Archived from the original on May 31, 2021. Retrieved October 11, 2022.
- ^ "1. Extending Python with C or C++". Python 3.10.7 documentation. Archived from the original on November 5, 2012. Retrieved October 11, 2022.
- ^ Conrad, Michael (January 22, 2018). "An overview of the Perl 5 engine". Opensource.com. Archived from the original on May 26, 2022. Retrieved October 11, 2022.
- ^ "To Ruby From C and C++". Ruby Programming Language. Archived from the original on August 12, 2013. Retrieved October 11, 2022.
- ^ Para, Michael (August 3, 2022). "What is PHP? How to Write Your First PHP Program". freeCodeCamp. Archived from the original on August 4, 2022. Retrieved October 11, 2022.
- ^ Dr. Dobb's Sourcebook. U.S.: Miller Freeman, Inc. November–December 1995.
- ^ "Using C for CGI Programming". linuxjournal.com. March 1, 2005. Archived from the original on February 13, 2010. Retrieved January 4, 2010.
- ^ Perkins, Luc (September 17, 2013). "Web development in C: crazy? Or crazy like a fox?". Medium. Archived from the original on October 4, 2014. Retrieved April 8, 2022.
- ^ Munoz, Daniel. "After All These Years, the World is Still Powered by C Programming". Toptal Engineering Blog. Retrieved November 17, 2023.