Modern C
and what we can learn from it
By Luca Sas
Modern C?
Modern C?
Goals
Goals
Goals
Goals
About me
Core Systems Engineer @ Creative Assembly
Game Development
Low Level Systems
Programming Languages
BananyaDev#0001
@SasLuca
sas.luca.alex@gmail.com
@
A refresh on C
A refresh on C
A refresh on C
A refresh on C
A refresh on C
A refresh on C
Variables and structs
Variables and structs
Primitive types
Primitive types
Primitive types
Functions
C++ is not C
C++ is not C
C++ is not C
What else is different between C and C++?
Struct initialization
Struct initialization
Struct initialization
Struct initialization
Struct initialization
Struct initialization
Struct initialization
Struct initialization
Struct initialization
Struct initialization
Struct initialization
Struct initialization
Struct initialization
Struct initialization
Struct initialization
Struct initialization
Struct initialization
Struct initialization
Struct initialization
Struct initialization: sokol gfx
Struct initialization: sokol gfx
What Modern C is
What Modern C is
What Modern C is
What Modern C is
C11 Additions
C11 Additions
C11 Additions: static assert
C11 Additions: _Generic and overloading
C11 Additions: Atomic operations
C11 Additions: thread_local
C11 Additions: thread_local
C11 Additions
Awesome Macros
Awesome Macros
Awesome Macros
Awesome Macros: defer
Awesome Macros: defer
Awesome Macros: defer
Awesome Macros: defer
Awesome Macros: defer
Awesome Macros: defer
API Design
API Design: Math
API Design: Math
- Out params are harder to spot at the call site
API Design: Math
- Out params are harder to spot at the call site
- There are indirection and aliasing issues caused by the pointers which can harm performance
API Design: Math in Modern C
- value oriented design
API Design: Math in Modern C
- value oriented design
- we can use literals in the function call and readability is improved
API Design: Math in Modern C
- value oriented design
- we can use literals in the function call and readability is improved
- performance is actually better
API Design: Math in Modern C
API Design: Error handling
API Design: Error handling
API Design: Error handling
API Design: Error handling
API Design: Error handling in Modern C
Error handling in Modern C
Error handling in Modern C
Error handling in Modern C
Error handling in C++ with optional
Error handling in Modern C
Error handling in Modern C
Error handling in Modern C
Error handling: std::expected
Error handling in Rust
Error handling in Zig
Error handling in C++
Generic APIs in C
Generic APIs in C
Generic APIs in C
Generic APIs in C: Trees and Graphs
Generic APIs in C: Trees and Graphs
Generic APIs in C: Dynamic Arrays
Generic APIs in C: Dynamic Arrays
Generic APIs in C: Dynamic Arrays
Generic APIs in C: Dynamic Arrays
Generic APIs in C: Map
https://github.com/nothings/stb/blob/master/stb_ds.h
Libraries in C
Libraries in C
Libraries in C
Libraries in C
Great talk on Cmake
Libraries in newer languages
When writing libraries
When writing libraries
When writing libraries
Memory management
Temporary allocators
Temporary allocators
Temporary allocators
API Design: Modern C
String handling in C
String handling in C
Public service announcement: avoid libc
Replacing libc functionality: printf
String handling in C
It’s not just null terminated strings
Case study: std::string
Intent: reading an array of bytes representing text
Case study: std::string
What’s the problem with a few couple of temporary strings here and there?
Real life examples:�Chrome
Real life examples:�Chrome
Real life examples:�Chrome
String handling in Modern C
String handling in Modern C
String handling in Modern C
String handling in Modern C
String handling in Modern C
String handling in Modern C
String handling in Modern C
String handling in Old C
String handling in Old C
String handling in Modern C
String handling in Modern C: overloading
String handling in Modern C: overloading
String handling in Modern C: another awesome macro
String handling in Modern C: another awesome macro
First optimization at CA
First optimization at CA
First optimization at CA
First optimization at CA
String handling in other languages
String handling in C++
In conclusion
In conclusion
In conclusion
In conclusion
Shoutouts
Modern C for C++ Peeps: https://floooh.github.io/2019/09/27/modern-c-for-cpp-peeps.html
�Odin: https://odin-lang.org/
Zig: https://ziglang.org/
Handmade Hero: https://handmadehero.org/��Handmade Network: https://handmade.network/