Delight?
Book: Hacker’s Delight
Page: Preface (yes…)
<quote>”The hacker’s work may be useful or may be just a game. As an example of the latter, more than one determined hacker has written a program which, when executed, writes out an exact copy of itself.” “The shortest such program written in C, known to the present author, is by Vlad Taeerov and Rashit Fakhreyev and is 64 characters in length:
main(a){printf(a,34,a="main(a){printf(a,34,a=%c%s%c,34);}",34);}
</quote>
The book is authored by someone who has been hacking code since 1972. That however, doesn’t discount the fact the book fails to note the above code relies on many factors that are compiler, and machine-dependent, and may not even work on many platforms.
To hint a couple of them, the code relies on the size of pointer-to-int is more than, or equal to size of pointer-to-char*. Secondly, it relies upon the order of evaluation of paramters to printf (What happens if the second argument is evaluated after the first?). As per the C99 standard, there’s no guarantee on the order of evaluation of function’s parameters. Since this book was published much later (2002), I would expect such ‘notes’ in the book.
I’ve just started reading the book…
Update (Oct 10 2005): As I read the book, it seems like I was looking at a dimension the book should never have been measured at. Looking at whether that program complies to C99 or not, would strip the hack of all the fun.