Skip to content

Commit dacb883

Browse files
Merge pull request #60 from KrzysztofSzewczyk/master
C part
2 parents 20ed96d + 2390c42 commit dacb883

8 files changed

Lines changed: 112 additions & 1 deletion

File tree

.mdlintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"default": true,
33
"MD026": {
4-
"punctuation": ".,;:!"
4+
"punctuation": ",;:"
55
},
66
"MD013": {
77
"line_length": 300

book/SUMMARY.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,18 @@
171171

172172
* [Conclusion](languages/perl/conclusion.md)
173173

174+
* [C](languages/c/README.md)
175+
176+
* [Introduction](languages/c/intro.md)
177+
178+
* [History](languages/c/history.md)
179+
180+
* [Advantages](languages/c/advantages.md)
181+
182+
* [Disadvantages](languages/c/disadvantages.md)
183+
184+
* [Conclusion](languages/c/conclusion.md)
185+
174186
## End
175187

176188
* [Credits](credits.md)

book/languages/c/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Welcome
2+
3+
> This chapter has been authored by Krzysztof Szewczyk "Παλαιολόγος".
4+
5+
Welcome to the C chapter! I'd like to let you know a bit more about second most popular language.

book/languages/c/advantages.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Advantages
2+
3+
There are a lot of programmers that think C is not language worth learning. Let's review this. C was originally developed for
4+
the UNIX operating system by Dennis Ritchie. It's quite simple, is not tied to any particular hardware or operating system. **If
5+
some platform has C compiler, it's worth attention**. C is really general purpose language, so this way **it's so common**. This
6+
makes **it easier to write programs that will run without any changes on practically all machines that have POSIX compiliant
7+
API's**. The C language is a middle-level language as it combines the elements of high-level languages (structures, unions,
8+
enums, functions, conditionals) with the functionalism of assembly language. **It's possible to simulate OOP in C and write an
9+
operating system. C allows the manipulation of nearly everything** giving the programmer more control over exactly how the
10+
program will behave and more direct access to the mechanics of the underlying hardware, **while keeping application fully
11+
portable**. C is often quoted as cross-platform assembly. **C is still one of the most popular programming languages out there
12+
[at the time of writing it was 2nd language overall](https://www.tiobe.com/tiobe-index/). Overall, C was first most common
13+
language from 1988 to 2013! It's Popularity is still growing. In the year of writing, C had the highest rise in ratings in a
14+
year.** C is everywhere. Your keyboard is very propably powered by C, same as your fridge or even modem. **Microsoft Windows was
15+
developed in C and has nearly 90% market share. Same as Linux, MacOS, iOS, Android and Windows Phone.** The world’s most popular
16+
databases, including **Oracle Database, MySQL, MS SQL Server, and PostgreSQL are developed in C**. 3D movies are created with
17+
applications that are generally written in C and C++. The alarm clock that wakes you up is likely programmed in C. Then you use
18+
your microwave or coffee maker to make your breakfast. They are also embedded systems and therefore are probably programmed in
19+
C. You turn on your TV or radio while you eat your breakfast. Those are also embedded systems, powered by C. When you open your
20+
garage door with the remote control you are also using an embedded system that is most likely programmed in C. You park your
21+
car, go to the shop and use vending machine to get a soda. What language did they use to program this vending machine? Probably
22+
C. Then you buy something at the store. The cash register is also programmed in C. And when you pay with your credit card? The
23+
credit card reader is, again, likely programmed in C. **There are many programming languages, today, that allow developers to be
24+
more productive than with C for different kinds of projects. There are higher level languages that provide much larger built-in
25+
libraries that simplify working with JSON, XML, UI, web pages, client requests, database connections, media manipulation, and so
26+
on. But despite that, there are plenty of reasons to believe that C programming will remain active for a long time.** In
27+
programming languages one size does not fit all. Here are some reasons that C is unbeatable, and almost mandatory, for certain
28+
applications. **Arbitrary memory address access and pointer arithmetic is an important feature that makes C a perfect fit for
29+
system programming (operating systems and embedded systems).** **A common language feature that system programming cannot rely
30+
on it's garbage collection, or even just dynamic allocation for some embedded systems. Embedded applications are very limited in
31+
time and memory resources. They are often used for real-time systems, where a non-deterministic call to the garbage collector
32+
cannot be afforded. And if dynamic allocation cannot be used because of the lack of memory, it is very important to have other
33+
mechanisms of memory management, like placing data in custom addresses, as C pointers allow.** Languages that depend heavily on
34+
dynamic allocation and garbage collection wouldn’t fit for resource-limited systems. **C has a very small runtime. And the
35+
memory footprint for its code is smaller than for most other languages.** When compared to C++, for example, a C-generated
36+
binary that goes to an embedded device is about half the size of a binary generated by similar C++ code. One of the main causes
37+
for that is exceptions support. Exceptions are a great tool added by C++ over C, and, if not triggered and smartly implemented,
38+
they have practically no execution time overhead (but at the cost of increasing the code size). **C is a lingua franca for
39+
developers. Many implementations of new algorithms in books or on the internet are first (or only) made available in C by their
40+
authors.** This gives the maximum possible portability for the implementation. I’ve seen programmers struggling on the internet
41+
to rewrite a C algorithm to other programming languages because he or she didn’t know very basic concepts of C.
42+
43+
## The Illuminati doesn't run the world. C programmers do!

book/languages/c/conclusion.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Conclusion
2+
3+
C is excellent language for embedded development. It's mixture of lower level programming, which is possible in C (see BIOS
4+
implemented in C; Linux kernel was implemented in C too), but also higher level programming - there is theoretical possibility of
5+
OOP simulation in C, getting rid of the part where C is not shining.
6+
7+
One thing is sure - **nothing, ever** will replace C. C will remain ruling IT world, **[forever](https://www.tiobe.com/tiobe-index/)**.

book/languages/c/disadvantages.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Disadvantages
2+
3+
C has no support for closures, no guaranteed support of tail calls
4+
5+
There is no way to portably inspect the call stack. Hence, you cannot code something like GNU backtrace or `longjmp`/`setjmp` in
6+
portable C. Also, coding precise garbage collectors is very painful.
7+
8+
There is no ABI, every vendor made up their own. Higher level constructs have to be manually created or third-party libraries and
9+
other solutions used.
10+
11+
There are no namespaces, so it's easy to pollute global namespace and wreck something up.
12+
13+
Finally, C doesn't support exceptions and object oriented programming.

book/languages/c/history.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# History
2+
3+
Back in the day C was closely tied to the UNIX operating system, originally implemented in assembly language on a PDP-7 by Dennis
4+
Ritchie and Ken Thompson, incorporating several ideas from colleagues. Eventually, they decided to port the operating system to a
5+
PDP-11. The original PDP-11 version of Unix was developed in assembly language. Thompson needed a programming language for UNIX
6+
utilities. At first, he tried to make a Fortran compiler, but soon gave up the idea and made a new language B language, Thompson's
7+
simplified version of BCPL. However, small amount of utilities were made using B, because of it's unsatisfying efficency. Also, B
8+
could not take advantage of some of the PDP-11's features such as byte addressability.
9+
10+
In 1972, Ritchie started to improve B, which resulted in creating a new language - C. C compiler and some utilities made were later
11+
included in Unix. At Version 4 Unix (1973), the kernel was extensively re-implemented in C. By this time, the C language had
12+
acquired some powerful features.
13+
14+
Unix was one of the first operating system kernels implemented in a language other than assembly. In around 1977, Ritchie and
15+
Stephen C. Johnson made further changes to the language to facilitate portability of the Unix operating system. Johnson's Portable
16+
C Compiler served as the basis for several implementations of C on new platforms.

book/languages/c/intro.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Introduction
2+
3+
**C** is a general-purpose, imperative programming language, supporting structured programming, lexical variable scope and
4+
recursion, with static, weakly enforced type system. C provides constructs that map to machine code, so it has found use in
5+
applications that had been coded in assembly language before, including operating systems, as well as various software for
6+
computers.
7+
8+
C is an imperative procedural language. It was designed to be compiled using simple compiler, to provide low level stuff sufficent
9+
to replace a few tasks of assembly, and provide higher level language constructs that map efficiently to machine instructions,
10+
that require minimal run-time support, to increase usability of language.
11+
12+
Despite its low-level capabilities, the language has wide cross-platform programming capabilities. A C89 program
13+
that is written with portability in mind can be compiled for a very wide variety of platforms and operating systems with
14+
few or no changes to its source code. The language has become available on a very wide range of platforms, from embedded
15+
systems to supercomputers.

0 commit comments

Comments
 (0)