Are there any "design patterns" in C?

onemasse picture onemasse · Nov 6, 2010 · Viewed 55.4k times · Source

I know that design patterns is generally something that's connected to OO programming, but do you have some pattern you often use when you program C?

I'm not interested in simple translations of the classical OO patterns and please don't mention Duff's device. ;-)

Answer

coolaj86 picture coolaj86 · Feb 3, 2012

My favorite is the "Patterns in C" series by Adam Tornhill:

Also: I always think of goto as a great poor man's tool for the decorator pattern.

Update: I'd highly recommend using Rust (rust-lang.org) rather than C except where you are required to use c. Rust has all of the benefits of c, including speed and binary library compatibility with c, but the compiler handles much of the complexity to ensure that the code is memory safe and does not contain data races. It's also portable, has a standard library for common tasks, and much easier to program with for various design patterns.