Modern C on Sea

Dawid Zalewski

half-day workshop
15:30-19:15, Thursday, 1st July 2021

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.

  1. Quiz: test your C knowledge.
  2. C for C++ programmers in three slides: auto, aliasing, void*, _Bool, void and more.
  3. How to initialize everything in C: braces, default values and designators.
  4. Arrays: dynamic, static and VLA's.
    • Variable length arrays: pros, cons, real performance costs.
    • VLA pointers.
  5. Passing pointers and arrays to functions: syntax, compiler checks and guidelines.
  6. Compound literals - the magic of unnamed objects.
    • Compound literals - what are they?
    • Applications: pointers, assignments, function arguments.
    • Under the hood - compilers vs. compound literals.
  7. Activity: Modernize code with designated initializers and compound literals, guidelines and performance.
  8. Flexible array members in structures.
  9. Anonymous structs and unions.
  10. Don't be afraid of values - performance of values semantics.
  11. Generic programming in C.
  12. Exit quiz: what you've learned.

Dawid Zalewski

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.