가끔 의미를 확인하기 위해 매우 짧은 것을 시도하고 싶습니다. 임시 파일을 생성하고 30 초 이상을 보일러에 넣어 걸리므로, 나는이 스크립트가 :
#!/bin/sh
body="$1"
out=$(mktemp /tmp/ccrun-XXXXXX)
src=${out}.c
cat > ${src} <<EOF
#include <limits.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define UNUSED __attribute__((unused))
int main(int UNUSED argc,char UNUSED *argv[])
{
EOF
echo "$body" >> ${src}
echo -e "return 0;\n}" >> ${src}
cc -std=c99 -Wall -Wextra ${CCRUN_FLAGS} -o ${out} ${src} -lm
shift
echo ${out} "[email protected]"
${out} "[email protected]"
#rm ${out} ${src}
샘플 호출 (이 코드는 정적 함수 포인터의 배열을 초기화)을 보이는 같은 :
$ 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 %d\n",i,farr[i](i));'
/tmp/ccrun-6nT4Wo
0 1
1 3
약간 변경하고 싶다면 명령 줄을 편집하면됩니다. 명령 줄에서 다루기 힘들어지면 임시 파일을 편집합니다 (이 경우 /tmp/ccrun-6nT4Wo.c
). 명령 줄 실행 파일에 대한 인수는 프로그램 뒤에 지정할 수 있습니다 (먼저 인수). 실행 파일은 그대로 두어 다시 컴파일하지 않고 을 실행할 수 있습니다. 언어에 대해 비슷한 작업을 수행 할 수 있습니다.
출처
2008-11-09 20:24:47
Jed
관련 : [좋은 온라인 IDE가 있습니까?] (http://stackoverflow.com/questions/491721/) –