This is a neat hack, but the whole file is not a valid C program.
Isn't that already legitimized by configure scripts, compiler command lines and Make files?
"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