Shebang
Zack Weinberg
zack@codesourcery.com
Mon Mar 8 20:44:00 GMT 2004
Leah <eequor@earthlink.net> writes:
> Hello. I was curious whether there was any possibility of making gcc
> ignore #! instead of viewing it as a directive.
I think #! is a constraint violation, which requires a diagnostic,
unfortunately.
> Also, are there reasons gcc won't compile directly from stdin to
> stdout?
GCC will, actually; it's the assembler and linker that won't. Try:
gcc -S -xc - -o - < file.c > file.s.
You could take this up with the binutils maintainers
(binutils@sources.redhat.com) but I believe there are good reasons why
this is infeasible at least for the linker.
> Along with other changes, these would make it easier to write C
> script files. They would certainly take more time to load, but
> scripts can be more convenient at times.
You are unfortunately going to run into even more trouble trying to
get the operating system to load an executable from stdin. Binary
executable loading works via mmap(), which cannot be applied to a
pipe.
I suggest you write a wrapper program like this (only in C - you can't
use a shell script as an #! interpreter):
---
tmpexec=`mktemp /tmp/exec.XXXXXX`
tail +2 "$1" | gcc -o "$tmpexec" -xc -
shift
"$tmpexec" "$@"; result=$?
rm -f "$tmpexec"
exit $result
---
that should do what you want.
zw
More information about the Gcc
mailing list