3 ms·
> TCC can also be treated much like an interpreter I assume you are aware, but tcc can be treated exactly like an interpreter: #!/usr/bin/tcc -run -lgmp #
by e12e 14y ago
> TCC can also be treated much like an interpreter
I assume you are aware, but tcc can be treated exactly like an interpreter:
#!/usr/bin/tcc -run -lgmp
#include<stdlib.h>
#include "gmp.h"
/* all this in eg. fac.c */
void factorial(mpz_t r, int n)
{
unsigned int i;
mpz_t tmp;
mpz_init(tmp);
mpz_set_ui(r,1);
for (i=1;i<=n;i++)
{
mpz_set_ui(tmp,i);
mpz_mul(r,r,tmp);
}
mpz_clear(tmp);
}
int main(int argc, char** argv)
{
mpz_t r;
mpz_init(r);
int n;
if (argc == 2)
{
n = atoi(argv[1]);
factorial(r, n);
gmp_printf("%d!:%Zd\n", n, r);
mpz_clear(r);
} else {
exit(1);
}
exit(0);
}
chmod a+x fac.c
time ./fac.c 1000
1000!:4023872(... snip for formating ...)000
real 0m0.007s
user 0m0.004s
sys 0m0.000s
edit: removed actual factorial, as hn formating choked on the long line.
edit #2: indentation/block formatting of code.
edit #3: missing "time" prefix...
- vidarh 14y agoYeah, I opted for a weaker claim as I've not actually tested how practical it is to use it that way in myself. I keep meaning to read through the tcc source..