Signature Program - Optimisation and Example

main">

Optimisation and Example

In order for the program, often of great complexity, which would usually be represented with many lines of code, to fit into a single line, many compression techniques are used. The following program prints out an ASCII art version of the Sierpinski triangle fractal, shown in the illustration:

main(c,r){for(r=32;r;) printf(++c>31?c=!r--,"n":cAn uncompressed "spelt out" version of this program may look like this:

#include int main(void) { int c = 0; int r = 32; while (r != 0) { c = c + 1; if (c > 31) { c = !r; /* same as c = 0 */ r = r - 1; printf("n"); } else { if (c < r) { printf(" "); } else { if ((~c & r) != 0) { printf(" `"); } else { printf(" #"); } } } } return 0; }

Here we can see that many portions of code are missing from the signature program, most obviously the lack of #include , no return type of main as well as the use of non-standard main(c,r). The ?: operator plays a vital role in reducing the overall size of the program, allowing a single expression to replace the sizeable number of if/else logical conditionals. Size is also dramatically reduced by removing all whitespace and line breaks.

Signature programs often make use of undocumented or lesser-known features or quirks in a particular compiler which allow for smaller overall program size, as well as obscurity.

Read more about this topic:  Signature Program