【问题标题】:Getting flow control warning for a Lisp interpreter I wrote in C为我用 C 编写的 Lisp 解释器获取流控制警告
【发布时间】: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 但它仍然出错...有什么想法吗?

标签: c lisp


【解决方案1】:

你的函数有两种方法可以在不返回的情况下结束:

  1. last&gt;=first &amp;&amp; in_special(first) 为真时。
  2. is_function(seg[first]) 为真时。

【讨论】:

  • 抱歉,我没关注?
  • 您的函数中有两个地方包含if,正如我在回答中所指出的那样。只有当这两个条件都为假时,才会到达return scope 行。
猜你喜欢
  • 1970-01-01
  • 2022-01-20
  • 1970-01-01
  • 1970-01-01
  • 2010-11-14
  • 2017-01-27
  • 1970-01-01
  • 1970-01-01
  • 2011-10-16
相关资源
最近更新 更多