/* test_quine.c — a C quine: running it prints its own source. * * How it works: the file is a fixed point of a "quinate" function. * The two strings below are that function's data; everything around * them is code that re-emits the data verbatim, spliced back into the * same program shape. No argv, no /proc/self, no tricks — just two * printf calls. * * Build: musl-gcc -std=gnu11 -Oz -Wall -Wextra -o test_quine tests/test_quine.c * Check: ./test_quine | diff - tests/test_quine.c (no output = quine) */ #include int main(void) { const char *s = "const char *s = \"%s\";\n" "const char *f = \"%s\";\n" "printf(f, s, s, f);\n" "return 0;\n"; const char *f = "int main(void) {\n" " %s printf(f, s, s, f);\n" " return 0;\n" "}\n"; printf(f, s, s, f); return 0; }