Skip to content

Instantly share code, notes, and snippets.

@fairlight1337
Last active August 14, 2019 16:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fairlight1337/8420929 to your computer and use it in GitHub Desktop.
Save fairlight1337/8420929 to your computer and use it in GitHub Desktop.
Hello World program compilable (/runnable) as both .py and .c(pp). Makes use of the #define preprocessor directive of C/C++ to make Python code invisible to the C compiler while using multiline comments from Python (""") to make C(++)-code invisible to the Python interpreter. Both programs just output "Hello World from both!", while each program…
#// This comment is invisible to both, Python and C(++).
#/*
# This multiline comment is also invisible to both.
#*/
#include <stdio.h>
#define pass void printstring(char* x) { printf("%s", x); printf("\n"); }
pass
#/*
print "Only visible to Python."
#*/
#define testing "\
"""
void onlyvisibletocpp() {
printf("Only visible to C(++).\n");
}
#undef testing
#define testing "\
"""
#define def void
#define x ) {};
#define print
def printmessage(
#define unused \
x):
print x
#undef print
#define printmessage(x) printstring((char*)x);
#undef pass
#define pass int main(int argc, char** argv) { \
printmessage("Hello World from both!")
pass
#undef pass
#define pass onlyvisibletocpp(); return 0; }
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment