Re:Tiny-C Compiler
by LukeShu on Monday March 13, 2023 @06:11PM
(#35143717)
You can only sort of do that with gcc/clang. The #if 0 trick relies on funny behavior that is in a few common shells. When you try to execve(2) a script without a proper #! shebang, the kernel will return ENOEXEC. Bash will check for ENOEXEC then check a few heuristics to see if it looks like a text file, and if it does, then it will try to run it as a shell script.
This means that your script will work when run from a shell, but won't work when exec()ed from a non-shell program, which is a weird foot-gun.
Re:Tiny-C Compiler
by vidarh on Tuesday March 14, 2023 @09:05AM
(#35150813)
That makes sense. When I checked the tcc command line I was mildly surprised to see you could do the #if 0 hack at all, so not surprised to hear it has severe limitations.
This means that your script will work when run from a shell, but won't work when exec()ed from a non-shell program, which is a weird foot-gun.