Today on a discussion about C vs C++ vs C# vs anything else in the world (quite typical among programmers) somebody introduced a C idiom completely unknown to me: the Duff’s device.
Please take some minutes to behold this impressive piece of thinking in code either in Google Groups, in this comment from the author or in the Wikipedia entry (it will take some 30 minutes to actually study it in depth)
Ok, actually you might even found curious what the discussion was about: for C# programmers, you know about the mandatory break; after a switch case that the compiler does not allow you to omit. Well, this is a life-saver against unwanted program flow for fallthroughs in a break, but it does not let you do things like… like Duff’s device!
With great power comes great responsibility, so they say, and after all, as pointed out in literature, like “Expert C programming: Deep C Secrets” (very reccommended book!) default fallthrough in C is wrong 97% of the time!

0 Responses to “duff’s device”