This commit is contained in:
Miloslav Ciz 2021-11-20 12:49:21 -06:00
parent a5a9021fa6
commit 966c393636
5 changed files with 33 additions and 14 deletions

29
c.md
View file

@ -4,30 +4,39 @@ C is a low-level, statically typed imperative compiled language, the go-to langu
C is usually not considered an easy language to learn because of its low level nature: it requires good understanding of how a computer actually works and doesn't prevent the programmer from shooting himself in the foot. Programmer is given full control (and therefore responsibility). There are things considered "tricky" which one must be aware of, such as undefined behavior of certain operators and raw pointers. This is what can discourage a lot of modern "coding monkeys" from choosing C, but it's also what inevitably allows such great performance -- undefined behavior allows the compiler to choose the most efficient implementation.
# History and Context
## History and Context
# Standards
## Standards
C is not a single language, there have been a few standards over the years since its inception in 1970s. The notable standards and versions are:
- K&R C: C as described by its inventors in the book *The C Programming Language*, before official standardization. This is kind of too ancient nowadays.
- C89/C90 (ANSI/ISO C): First fully standardized version, usable even today.
- C95: A minor update of the previous standard, adds wide character support.
- C99: Updated standard from the year 1999 striking a great balance between "modern" and "good old". This is a good version to use in LRS programs, but will be a little less supported than C89.
- C11: Updated standard from the year 2011. This one is too bloated and isn't worth using.
- C17/C18: Yet another update, yet more bloated and not worth using.
- **K&R C**: C as described by its inventors in the book *The C Programming Language*, before official standardization. This is kind of too ancient nowadays.
- **C89/C90 (ANSI/ISO C)**: First fully standardized version, usable even today.
- **C95**: A minor update of the previous standard, adds wide character support.
- **C99**: Updated standard from the year 1999 striking a great balance between "modern" and "good old". This is a good version to use in LRS programs, but will be a little less supported than C89.
- **C11**: Updated standard from the year 2011. This one is too [bloated](bloat.md) and isn't worth using.
- **C17/C18**: Yet another update, yet more bloated and not worth using.
LRS should use C99 or C89 as the newer versions are considered [bloat](bloat.md) and don't have such great support in compilers, making them less portable and therefore less free.
The standards of C99 and older are considered pretty [future-proof](future_proof.md) and using them will help your program be future-proof as well. This is to a high degree due to C having been established and tested better than any other language; it is one of the oldest languages and a majority of the most essential software is written in C, C compiler is one of the very first things a new hardware platform needs to implement, so C compilers will always be around, at least for historical reasons. C has also been very well designed in a relatively minimal fashion, before the advent of modern feature-creep and and bullshit such as [OOP](oop.md) which cripples almost all "modern" languages.
# Compilers
## Compilers
- gcc
- clang
- tcc
- scc
# Basics
## Standard Library
So the standard library (libc) is a subject of live debate because while its interface and behavior are given by the C standard, its implementation is a matter of each compiler; since the standard library is so commonly used, we should take great care in assuring it's extremely well written. As you probably guessed, the popular implementations ([glibc](glibc.md) et al) are [bloat](bloat.md). Better alternatives thankfully exist, such as:
- [musl](musl.md)
- [uclibc](uclibc.md)
- [not using](dependency.md) the standard library :)
## Basics
A simple program in C looks like e.g. like this: