Skip to content

Instantly share code, notes, and snippets.

@8051Enthusiast
Created April 19, 2020 21:13
Show Gist options
  • Save 8051Enthusiast/f456cd52569bd2971ac479bbde41d5ab to your computer and use it in GitHub Desktop.
Save 8051Enthusiast/f456cd52569bd2971ac479bbde41d5ab to your computer and use it in GitHub Desktop.
preprocess with `gcc -E -std=c99 quine.c -o quine.i` and compile with `gcc -std=gnu99 quine.i -o quine`
#include <stdio.h>
#ifdef A
R"("
#else
#define A
const char *s =
#include __FILE__
;
#undef A
#endif
int main() {
char* pre = "#include <stdio.h>\n#ifdef A\nR\"(\"\n#else\n#define A\nconst char *s =\n#include __FILE__\n;\n#undef A\n#endif\n";
char* post = "#ifdef A\n\")\"\n#endif\n";
printf("%s%.235s%s",pre,s+9,post);
return 0;
}
#ifdef A
")"
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment