code_junkie

Tools for code snippet execution

Nov 12th, 2011
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. body="$1"
  4. out=$(mktemp /tmp/ccrun-XXXXXX)
  5. src=${out}.c
  6. cat > ${src} <<EOF
  7. #include <limits.h>
  8. #include <string.h>
  9. #include <math.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <stdint.h>
  13.  
  14. #define UNUSED __attribute__((unused))
  15.  
  16. int main(int UNUSED argc,char UNUSED *argv[])
  17. {
  18. EOF
  19. echo "$body" >> ${src}
  20. echo -e "return 0;n}" >> ${src}
  21. cc -std=c99 -Wall -Wextra ${CCRUN_FLAGS} -o ${out} ${src} -lm
  22. shift
  23. echo ${out} "$@"
  24. ${out} "$@"
  25. #rm ${out} ${src}
  26.  
  27. $ ccrun 'int f(int a){return a+1;} int g(int a){return a+2;} int (*farr[2])(int) = {f,g}; for (int i=0; i<2; i++) printf("%d %dn",i,farr[i](i));'
  28. /tmp/ccrun-6nT4Wo
  29. 0 1
  30. 1 3
Add Comment
Please, Sign In to add comment