diff --git a/clang.md b/clang.md index 3ad1b58858a5cfeda758493efe936e0290f752fb..d665279866a61304cf46b91fc0ab2704f4f80fb9 100644 --- a/clang.md +++ b/clang.md @@ -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: - - - -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: + + + +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 +```