You can also do what I do now (the example in my first message), and don't need to
pre-process the file before sending it to the compiler. What Jonothan suggested
("Still it would be a nice touch ...") would be great - but simply being able
use a custom script to (like I do in the example) without all the convolutions I used to
make it work - would be a good solution.
My goal would just be to have C, C++, etc, simply ignore the "#!" line, if it
is the very first line.
If you want to have additional lines, have it ignore everything until it sees an
"#end" (or some other token).
Basically "#!" would become a special comment (but would only work if the file
essentially started with it - first non-blank characters).
Think of users who use scripts all the time, but rarely use Compiled languages.
On 2024-12-28 4:47 PM, Florian Weimer wrote:
* Jonathan Wakely via Gcc:
Here's a complete example:
#!/bin/sh
set -e
out=$(mktemp /tmp/a.out.XXXXXX)
sed 1,5d "$0" | gcc -x c - -o "$out"
exec "$out"
#include <stdio.h>
int main()
{
puts("Hello, world");
return 0;
}
Or this, with accurate locations for diagnostics and argument
handling:
#!/bin/sh
set -e
out=$(mktemp /tmp/a.out.XXXXXX)
(echo "#line 6 \"$0\""; sed 1,5d "$0") | gcc -x c - -o "$out"
exec "$out" "$@"
#include <stdio.h>
int main()
{
puts("Hello, world");
return 0;
}
Still it would be a nice touch if we could do
#!/usr/bin/gcc -f
#include <stdio.h>
int main()
{
puts("Hello, world");
return 0;
}
instead.
--
--------------------------------------------------------
The views and opinions expressed above are strictly
those of the author(s). The content of this message has
not been reviewed nor approved by any entity whatsoever.
--------------------------------------------------------
Paul FM Info: http://paulfm.com/~paulfm/
--------------------------------------------------------