POSIX C
- Mutexes and Semaphores Demystified, 2016-05-04, by Michael Barr
C Language Standards
Evolution of C Standards
C89 / ISO C90 (1989/1990), First standardized version of C by ANSI (C89) and ISO (C90), key features:
- Function prototypes (stronger type checking).
const,volatile, andsignedkeywords.- Standard library defined (
stdio.h,stdlib.h, etc.). - Only
/* … */style comments. - Identifiers: only first 6 characters of external names guaranteed significant.
C99 (1999), Introduced modern language features:
//single-line comments.- Variable-length arrays (VLAs).
- inline functions.
restrictkeyword for pointer aliasing optimization.- New data types:
long long int,_Bool, complex numbers (<complex.h>). - Improved standard library:
snprintf, flexible math functions. - Designated initializers and compound literals.
- Mixed declarations and code (no longer required to declare all variables at top).
- Wide character support (
wchar_t,<wchar.h>). - Flexible array members in
structs.
C11 (2011), Focused on concurrency, safety, and portability:
- Multithreading support:
<threads.h>library. - Atomic operations: _Atomic keyword and
<stdatomic.h>. - Thread-local storage:
_Thread_local. - Static assertions:
_Static_assert. - Generic selections:
_Genericfor type-generic macros. - Alignment control:
_Alignas,_Alignof. - Improved Unicode support:
char16_t,char32_t. - Optional bounds-checking interfaces:
<bounds.h>. - Safer programming model with clearer memory consistency rules.
References
- C language documentation - Learn to use C and the C runtime library. https://learn.microsoft.com/en-us/cpp/c-language/?view=msvc-170
Coding Style Guide & Formatter
Use only spaces, and indent 2 spaces at a time.
All files encoding in UTF-8, with LF line of end, except Windows BAT script.
naming rules
- snake_case
- camelCase
- PascalCase
- snakesnake: all lower and no spaces
- snake-minus: all lower and concatenate with minus
- SNAKE_CASE_UPPER: all upper and concatenate with underline
naming entity
| entity | rule | example |
|---|---|---|
| structure | PascalCase | struct UrlTableProperties { ...} |
| structure data member | snake_case | |
| variable | snake_case | a_local_variable, a_struct_data_member |
| function | PascalCase | |
| constant | camelCase, snake_case | |
| macro | SNAKE_CASE_UPPER | #define MY_PROJECT_ROUND(x) ... |
| enum | PascalCase | enum Status { ...} |
| enum data member | camelCase | |
| typedef | PascalCase | |
| filename | snake_case, snake-minus, snakesnake | |
| test | snake_case | foo_test.c |
OOP
| entity | rule | | ------------------ | ---------- | --------------------- | | Namespace Name | snake_case | | public function | PascalCase | | class | PascalCase | | Class Data Members | snake_case | | | variable | snake_case | a_class_data_member |
Visual Studio Code - Code formatting
https://code.visualstudio.com/docs/cpp/cpp-ide#_code-formatting
Google C++ Style Guide
https://google.github.io/styleguide/cppguide.html
Linux kernel coding style
https://www.kernel.org/doc/html/v4.10/process/coding-style.html
Common libraries
SDL
SDL(Simple DirectMedia Layer) is a cross-platform development library designed to provide low level access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL and Direct3D. It is used by video playback software, emulators, and popular games including Valve's award winning catalog and many Humble Bundle games.
Tutorials
