【发布时间】:2015-03-25 13:57:27
【问题描述】:
我一直在研究 SICP,并尝试创建 LISP 解释器。我不断收到以下警告:
$ make littleLisp
cc littleLisp.c -o littleLisp
littleLisp.c:309:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
1 warning generated.
$ make littleLisp
make: `littleLisp' is up to date.
$ ./littleLisp
warning: this program uses gets(), which is unsafe.
5.000000
我不太确定这是指什么,因为我的主要方法返回 0。我的“in.lisp”文件没有被正确调用吗?
代码如下:
https://gist.github.com/rahul1346/8596118b834ecf41b1d9
有什么想法吗?
另外,你对交互者本身有什么看法?
这是以 309 结尾的 fxn:
long interpret_list(long scope, long first, long last) {
parent[first] = scope;
// printf("interpret_list %d %d %d\n", scope, first, last);
long i, j, brace;
if (last>=first && in_special(first)) {
// puts("OK");
special(scope, first, last);
} else {
child_count[scope] = 0;
i = j = first; brace = 0;
while ( i <= last) {
if (!strcmp(seg[i], "(")) brace++;
if (!strcmp(seg[i], ")")) brace--;
if (brace == 0) {
interpret(scope, j, i);
child[scope][child_count[scope]++] = j;
j = i + 1;
}
i++;
}
if (brace) {
// puts("Format error!!");
exit(2);
}
if (is_function(seg[first])) {
apply_function(seg[first], scope);
} else {
return scope;
}
}
}
【问题讨论】:
-
查看“LittleLisp.c”第 309 行结束的函数。哦,找到你在哪里使用
gets并将其替换为其他选项(例如,fgets)。 -
它正在返回范围?
-
存在不返回值的路径
-
知道为什么我会出现gets错误吗?我使用 fgets 但它仍然出错...有什么想法吗?