3 ms·
This is a neat hack, but the whole file is not a valid C program.
by enriquto 1y ago
This is a neat hack, but the whole file is not a valid C program.
- kazinator 1y agoYou mean it consists of a C program, plus non-C cruft to get it running? Isn't that already legitimized by configure scripts, compiler command lines and Make files?
- enriquto 1y agoof course it is legitimized. I just meant that the selling point of binfmtc is that the same .c file can either be compiled by any C compiler, or executed directly.
- kazinator 1y agoWe could perhaps split it into a two-file system where a "foo.sh" containing certain boilerplate will execute a "foo.c" that doesn't require any special conventions at all. "foo.sh" could be identical for any .c file, and so we could symbolically link them all to a common file. Of course, neither that file nor symlinks to it require a .sh suffix. The contents might look like this: #!/bin/sh c_file=${0%.sh}.c x_file=${0%.sh}.bin # If cached executable file is missing, or out of date w.r.t. # the source file, compile it: if [ "$c_file" -nt "$x_file" ]; then cc $CFLAGS "$c_file" -o "$x_file" fi # Run cached executable file $x_file