This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Shebang
- From: Zack Weinberg <zack at codesourcery dot com>
- To: Leah <eequor at earthlink dot net>
- Cc: gcc at gcc dot gnu dot org
- Date: Mon, 08 Mar 2004 12:44:20 -0800
- Subject: Re: Shebang
- References: <20040308142442.3d3ea98c.eequor@earthlink.net>
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