The Art in Code

Snippets of famous, interesting, historically relevant or thought-provoking... code.


Website maintained by Filip Stanis Based on theme by mattgraham

001 - Duff’s device

Code snippet of Duff's device

Snippet source

Wikipedia article

Duff’s device is a famous snippet of C code that manually performs loop unrolling.

Manually unrolling loops is nowadays considered a bad practice, as most compilers perform this automatically behind the scenes.

However, the historical significance of Duff’s device remains: it reminds us that creativity can help us overcome limits introduced by abstraction created in a higher level language (in this case C as opposed to assembly).

Explanation

At least two good explanations are available that break this code down in detail: