Name: Anonymous 2008-03-20 0:37
How would I write an eval() function in C? Where do I start?
int eval(char **args) {
if (strcmp(args[0], "car") == 0) {
return car(args[1])
}
}
int eval(const char *code)
{
FILE *cc = popen("cc -o /tmp/eval.out -xc -", "w");
fputs(code, cc);
return pclose(cc) ? -1 : system("/tmp/eval.out");
}int i = 2; eval("i = 3"); printf("%d", i)#include's or specify a main function.strlen as well? (Yes, its use of temp files and probably shell commands is insecure, but that's not the point.)