Last active
November 13, 2022 21:30
-
-
Save hadrianw/5cd275d5838814d813adc12978dce9be to your computer and use it in GitHub Desktop.
Make a C file executable with those few lines.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if 0 | |
set -e; [ "$0" -nt "$0.bin" ] && | |
gcc -Wall -Wextra -pedantic -std=c99 "$0" -o "$0.bin" | |
exec "$0.bin" "$@" | |
#endif | |
#include <stdio.h> | |
int | |
main(int argc, char *argv[]) { | |
int ch = getchar(); | |
printf("Hello %c world!\n", ch); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah, it makes sense as you describe the whole behavior.
Basically I thought of TCC's and Dlang's
-run
flags; what I know for sure is that DMD would generate an executable at/tmp
, run it, and then delete it immediately.Of course as you have said yourself, the workarounds you have just shared (thank you by the way) are quite hacky and a bit verbose to say the least, therefore I should stick with your original preprocessor technique.
Thank you for your thorough explanation, I was reminded how script behavior works.