Skip to content

Instantly share code, notes, and snippets.

@fairlight1337
Last active Aug 14, 2019
Embed
What would you like to do?
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