Skip to content

Instantly share code, notes, and snippets.

@ljmccarthy
Created October 11, 2018 10:55
Show Gist options
  • Save ljmccarthy/4a42c0971694ab2763def37ae70327d6 to your computer and use it in GitHub Desktop.
Save ljmccarthy/4a42c0971694ab2763def37ae70327d6 to your computer and use it in GitHub Desktop.
Self-compile and run C file. chmod +x and ./run it!
#if 0
set -e
[ -z "$CC" ] && CC=$(which tcc clang gcc cc | head -1)
out="$(tempfile -p $(echo $(basename $0) | cut -f 1 -d '.'))"
$CC -pipe -x c -std=c99 -g -ftrapv -o $out "$0"
exec $out "$@"
#endif
#include <stdio.h>
int main(int argc, const char *const *argv) {
remove(argv[0]);
printf("hello, world!\n");
for (int i = 0; i < argc; i++) {
printf("argv[%d] = %s\n", i, argv[i]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment