3 ms·
For simple C or C++ programs I add this snippet at the beginning of the file: #if 0 set -e; [ "$0" -nt "$0.bin" ] && gcc -Wall -Wextra -pedantic -std=c99
by hawski 4y ago
For simple C or C++ programs I add this snippet at the beginning of the file:
#if 0
set -e; [ "$0" -nt "$0.bin" ] &&
gcc -Wall -Wextra -pedantic -std=c99 "$0" -o "$0.bin"
exec "$0.bin" "$@"
#endif
Then make the file executable and you can use it like a script. All the flags are just there and visible.
However it would be preferable to just have a smart enough language tooling to do it without such tricks.
- elitepleb 4y agohttps://web.archive.org/web/20210204050841/http://www.iq0.com/duffgram/com.html https://web.archive.org/web/20210204050841/http://www.iq0.co... implements the same idea
- monocasa 4y agotcc also allows you to run C with #/usr/bin/tcc -run at the beginning of the file. I use that all the time while prototyping C.
- stefanos82 4y agoVery nice! One question if I may: how can I erase "$0.bin" after its execution?