#!gcc - run c like a script language
Following the ideia on this post I tried to run C code using the same process and this is the result!
//bin/cat /dev/null; FILE="`mktemp -u -t bin`"; gcc -o "$FILE" "$0" && "$FILE" "$@"; exit
#include <stdio.h>
int main(int argc, char *argv[]) {
int i;
printf("Printing arguments.\n");
for (i = 0; i < argc; i++) {
printf("%d: %s\n", i, argv[i]);
}
}
Written by Tarcísio Gruppi
Related protips
1 Response
A great enhancement to this would be to detect changes in the file and only recompile when there have been changes. Could do this by hashing the file, naming the output off gcc using the hash, and not executing gcc again if the output file exists.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#