Skip to content
Snippets Groups Projects
Commit d480dbfb authored by Mactavish's avatar Mactavish
Browse files

restructure the document

parent 01d21ce4
No related branches found
No related tags found
No related merge requests found
......@@ -4,36 +4,6 @@ This document is not intended to be a primer on the C programming language. It o
We will focus on common errors, caveats and important concepts that might ease your cognitive overhead when you program in C. We will also recommend some tools that help you speed up your development and debugging.
## C Compilation Process
Unlike other interpreted programming languages, we use compilers to compile C written programs.
A full compilation in C is depicted in the following figure:
![](./images/c-compilation.png)
A detailed explanation can be found [here](https://www.scaler.com/topics/c/compilation-process-in-c/).
## C Macros
You often see C preprocessor macros defined to create "small functions"
But they **aren't actual functions**, it just changes the **text** of the program.
`#include` just copies that file into the current file and replace the arguments.
Example:
```c
#define twox(x) (x + x)
// twox(3); => (3 + 3);
// this could lead to unexpected behaviours
// int y = 2;
// int z = twox(y++); => z = (y++ + y++); the value of z actaully depends on the order of evaluation
```
## Specific Sized Numbers
C only guarantees minimum and relative size of "int", "short" etc... The range that each type can represent depends on the implementation.
......@@ -315,3 +285,39 @@ These are common in many codebases, and the first time you see them, you might b
`x = *p++` is actually doing `x = *p; p = p + 1;`.
`x = (*p)++` is actually doing `x = *p; *p = *p + 1;`.
## Arrays
## Strings
## C Memory Management
## C Compilation Process
Unlike other interpreted programming languages, we use compilers to compile C written programs.
A full compilation in C is depicted in the following figure:
![](./images/c-compilation.png)
A detailed explanation can be found [here](https://www.scaler.com/topics/c/compilation-process-in-c/).
## C Macros
You often see C preprocessor macros defined to create "small functions"
But they **aren't actual functions**, it just changes the **text** of the program.
`#include` just copies that file into the current file and replace the arguments.
Example:
```c
#define twox(x) (x + x)
// twox(3); => (3 + 3);
// this could lead to unexpected behaviours
// int y = 2;
// int z = twox(y++); => z = (y++ + y++); the value of z actaully depends on the order of evaluation
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment