On Sat, 28 Dec 2024, 16:17 Jonathan Wakely, <jwakely....@gmail.com> wrote:

>
>
> On Sat, 28 Dec 2024, 15:26 Paul Smith via Gcc, <gcc@gcc.gnu.org> wrote:
>
>> On Sat, 2024-12-28 at 09:00 -0600, Paul Markfort via Gcc wrote:
>> > I realize that C is not a line oriented language and usually
>> > completely ignores line termination characters (so yes this is
>> > probably not a simple thing to do).
>>
>> You probably really want this capability added to the preprocessor, not
>> the compiler.
>>
>> That's much simpler and will meet your needs just as well.
>>
>
> There's no need. The shebang line is going to involve some script anyway,
> so that script can just remove the first line and pipe the result to GCC.
>
>
> sed 1d $0 | gcc -x c - -o $out
>

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;
}

Reply via email to