Update shit
This commit is contained in:
parent
29840b371b
commit
cb6f066f97
2 changed files with 26 additions and 0 deletions
5
c.md
5
c.md
|
@ -4,6 +4,11 @@ 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.
|
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.
|
||||||
|
|
||||||
|
For more about C see:
|
||||||
|
|
||||||
|
- [C pitfalls](c_pitfalls.md)
|
||||||
|
- TODO
|
||||||
|
|
||||||
## History and Context
|
## History and Context
|
||||||
|
|
||||||
## Standards
|
## Standards
|
||||||
|
|
21
c_pitfalls.md
Normal file
21
c_pitfalls.md
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
# C Pitfalls
|
||||||
|
|
||||||
|
[C](c.md) is a powerful language that offers almost absolute control and maximum performance which necessarily comes with responsibility and danger of shooting yourself in the foot. Without knowledge of the pitfalls you may well find yourself fallen into one of them.
|
||||||
|
|
||||||
|
Unless specified otherwise, this article supposes the C99 standard of the C language.
|
||||||
|
|
||||||
|
## Undefined Behavior
|
||||||
|
|
||||||
|
Undefined behavior is any behavior that is not described in the specification of the language; this is mostly done on purpose as to allow some implementation freedom which allows implementing the language in a way that is most efficient on given platform. Undefined behavior may be completely random (unpredictable) or implementation-specified (consistent within each implementation but potentially different for each of them). In any case, it is highly advised to avoid any undefined behavior in absolute majority of cases. Description of some of the undefined behavior cases follow.
|
||||||
|
|
||||||
|
**Data type sizes including int and char may not be the same on each platform**. Even though we almost take it for granted than char is 8 bits wide, in theory it can be wider. The int (and unsigned int) type width should reflect the architectures native integer type, so nowadays mostly it's mostly 32 or 64 bits. To deal with this we can use the standard library `limits.h` and `stdint.h` headers.
|
||||||
|
|
||||||
|
**Char data type signedness is not defined**. The signedness can be explicitly "forced" by specifying `signed char` or `unsigned char`.
|
||||||
|
|
||||||
|
**Bit shifts by type width or more are undefined.** Also bit shifts by negative values are undefined. So e.g. `x >> 8` is undefined if width of the data type of `x` is 8 bits.
|
||||||
|
|
||||||
|
TODO
|
||||||
|
|
||||||
|
## Memory Unsafety
|
||||||
|
|
||||||
|
TODO
|
Loading…
Reference in a new issue