Sample Video Frame
Exercise 23: Meet Duff's Device
This exercise is a brain teaser where I introduce you to one of the most famous hacks in C called Duff's device, named after Tom Duff the inventor. This little slice of awesome (evil?) has nearly everything you've been learning wrapped in one tiny little package. Figuring out how it works is also a good, fun puzzle.
NOTE: Part of the fun of C is that you can come up with crazy hacks like this, but this is also what makes C annoying to use. It's good to learn about these tricks because it gives you a deeper understanding of the language and your computer. But, you should never use this. Always strive for easy to read code.
Discovered by Tom Duff, Duff's device is a trick with the C compiler that actually shouldn't work. I won't tell you what it does yet since this is meant to be a puzzle for you to ponder and try to solve. You'll get this code running and then try to figure out what it does, and why it does it this way.
Register for Learn C the Hard Way
Register today for the course and get the all currently available videos and lessons, plus all future modules for no extra charge.