Last active
August 14, 2019 16:35
-
-
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#// 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