Modern C on Sea
If you are a seasoned C++ programmer you might think about C as a prehistoric language stuck in the times of K&R. But have you ever heard about compound literals and about how they can be used to enable default function arguments in C? Or have you ever used flexible array members to simplify dynamic data structures creation? What about anonymous
unions, designated initialisers or
static array arguments? Never heard of those? C is a living language that has much to offer to those who care about performance, who program close to hardware or whose daily routine involves interfacing C++ with C code. If you are such a person, or you are just curious and would like to learn about the older, little brother of C++, this is a workshop for you. We will (re-)discover the perks and perils of modern C. Step by step, we’ll see how leveraging the latest language features helps readability, improves safety and leads to better runtime performance. Who knows, maybe you’ll find writing C enjoyable (again)?
Have a laptop with a recent C-standard compliant toolchain (gcc or clang-llvm) at hand. You’ll need it for exercises.
- Quiz: test your C knowledge.
- C for C++ programmers in three slides:
- How to initialize everything in C: braces, default values and designators.
- Arrays: dynamic, static and VLA's.
- Variable length arrays: pros, cons, real performance costs.
- VLA pointers.
- Passing pointers and arrays to functions: syntax, compiler checks and guidelines.
- Compound literals - the magic of unnamed objects.
- Compound literals - what are they?
- Applications: pointers, assignments, function arguments.
- Under the hood - compilers vs. compound literals.
- Activity: Modernize code with designated initializers and compound literals, guidelines and performance.
- Flexible array members in structures.
structs and unions.
- Don't be afraid of values - performance of values semantics.
- Generic programming in C.
- Exit quiz: what you've learned.
Dawid is a computer engineer with a heart for teaching. He's been programming for over 20 years evolving through Basic, Turbo Pascal and many other languages to finally find his home in the land of C++ (with occasional visits to C and Python). He teaches at Saxion University of Applied Sciences in the Netherlands, where he tries to convert new generations of programmers to use modern C++. Besides teaching, he uses C++ in the research on probabilistic state estimation for industrial applications. His interests focus on the design and evolution of programming languages and paradigms. In his free time he explores the evolving landscape of online teaching pedagogy or reads books.