Jan 10, 2013

Compiling C from stdin

allheads.h:
#include <math.h>
#include <time.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <gsl/gsl_rng.h>
Paste this onto your command line, or add it to your .bashrc, .zshrc, or wherever applicable:
go_libs="-lm"
go_flags="-g -Wall -include allheads.h -O3"
alias go_c="c99 -xc '-' $go_libs $go_flags"
And now we can use a here document to paste short C programs onto the command line:
go_c << '---'
int main(){printf("Hello from the command line.\n");}
---
# and then run:
./a.out

No comments: