Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
C script runs C code without temp space (tcc -run) and script stdin available to C
echo "foo"
tcc -run <(sed -n "/^\/\*\*$/,\$p" $0) 42
#include <stdio.h>
int main(int argc, char *argv[])
printf("bar %s\n", argv[1]);
for(int ch=getchar(); EOF!=ch; ch=getchar())
return 0;

This comment has been minimized.

Copy link
Owner Author

@Hermann-SW Hermann-SW commented Sep 16, 2021

Demos passing "42" as argv[1], and keeping C code stdin the same as C script stdin:

$ route -n | ./run_from_memory_stdin.c 
bar 42
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface         UG    306    0        0 wlan1   U     0      0        0 wlan0     U     303    0        0 wlan0 U     306    0        0 wlan1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment