Compiling C code without saving to file

Inspired by this PCG call: https://codegolf.stackexchange.com/q/61836/31033 I asked myself if I should try to leave as few traces as possible when compiling such a tool (regardless of browser or something else), is there any itโ€™s a way (aimed at gcc / clang, since itโ€™s probably a predefined command line for compilers in such a working environment) to pass the source code to the compiler as a command line argument or an equal mechanism, without requiring the source code to be saved as a * .c file, as the user usually did?

(Of course, the compiler will create temporary files at compile time, but they probably won't be scanned.)

+5
source share
1 answer

At least gcc can, since it can read the source from standard input. You can also use Unix here string bash construction:

 gcc -xc - << "int main() { exit(0); }" 

or here is the construction of the sh file:

 gcc -xc - <<MARK int main() { exit(0); } MARK 

---- EDIT ----

You can also imagine, using cryptography to encode your source, untwist content on the fly and enter the result on gcc standard input, something like:

 uncipher myfile.protected | gcc -xc - 
+6
source

Source: https://habr.com/ru/post/1234782/


All Articles