← Back to context

Comment by w4rh4wk5

2 hours ago

Back in the days, I've seen that with C files, which are compiled on the fly to a temporary file an run.

Something like //usr/bin/gcc -o main "$0"; ./main "$@"; exit

Tcc even supports that with `#!/usr/local/bin/tcc -run`, although I don't understand people who use c or go for "scripting", when python, ruby, TCL or perl have much superior ergonomics.

  • This was a relatively old project that used a C program as build system / meta generator. All you needed was a working C compiler (and your shell to execute the first line). From there, it built and ran a program that generated various tables and some source code, followed by compiling the actual program. The final program used a runtime reflection system, which was set up by the generated tables and code from the first stage.

    The main reason was to do all this without any dependencies beyond a C compiler and some POSIX standard library.