c++ - 警告 : control reaches end of non-void function (c++)

标签 c++ controls void

我收到这个错误并且无法修复,我还是菜鸟,如果有人能帮助我,我会感谢你 此代码来自 libxenon 的 xmplayer(用于 jtag xbox)

(我尝试搜索类似的错误,但我找不到问题所在)

  int FileSortCallback(const void *f1, const void *f2) {
    /* Special case for implicit directories */
    if (((BROWSERENTRY *) f1)->filename[0] == '.' || ((BROWSERENTRY *) f2)->filename[0] == '.') {
        if (strcmp(((BROWSERENTRY *) f1)->filename, ".") == 0) {
            return -1;
        }
        if (strcmp(((BROWSERENTRY *) f2)->filename, ".") == 0) {
            return 1;
        }
        if (strcmp(((BROWSERENTRY *) f1)->filename, "..") == 0) {
            return -1;
        }
        if (strcmp(((BROWSERENTRY *) f2)->filename, "..") == 0) {
            return 1;
        }
    }

    /* If one is a file and one is a directory the directory is first. */
    if (((BROWSERENTRY *) f1)->isdir && !(((BROWSERENTRY *) f2)->isdir)) return -1;
    if (!(((BROWSERENTRY *) f1)->isdir) && ((BROWSERENTRY *) f2)->isdir) return 1;

    //Ascending Name
    if (XMPlayerCfg.sort_order == 0) {
        return stricmp(((BROWSERENTRY *) f1)->filename, ((BROWSERENTRY *) f2)->filename);
    }
    //Descending Name
    else if (XMPlayerCfg.sort_order == 1) {
        return stricmp(((BROWSERENTRY *) f2)->filename, ((BROWSERENTRY *) f1)->filename);
    }
    //Date Ascending
    else if (XMPlayerCfg.sort_order == 2) {
        if ( ((BROWSERENTRY *) f2)->date == ((BROWSERENTRY *) f1)->date) { //if date is the same order by filename
            return stricmp(((BROWSERENTRY *) f2)->filename, ((BROWSERENTRY *) f1)->filename);
        } else {
            return ((BROWSERENTRY *) f1)->date - ((BROWSERENTRY *) f2)->date;
        }
    }
    //Date Descending
    else if (XMPlayerCfg.sort_order == 3) {
        if ( ((BROWSERENTRY *) f2)->date == ((BROWSERENTRY *) f1)->date) { //if date is the same order by filename
            return stricmp(((BROWSERENTRY *) f1)->filename, ((BROWSERENTRY *) f2)->filename);
        } else {
            return ((BROWSERENTRY *) f2)->date - ((BROWSERENTRY *) f1)->date;
        }
    }
}

最佳答案

编译器分析您的代码,发现将对 05 之间的所有 sort_order 值执行 return 语句,包括.但是,如果 sort_order 为负数或大于 5,则代码将到达函数末尾而没有 return 语句;这就是编译器发出警告的原因。

请注意,由于代码其他部分的限制,可能无法将 sort_order 设置为负数或大于 5 的数字。然而,编译器不知道这些,所以它认为 sort_order 可能有任何值。

要解决此问题,请在末尾添加无条件返回语句。

关于c++ - 警告 : control reaches end of non-void function (c++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13216022/

相关文章:

c++ - 即使我的 if 语句成立,我也遇到了麻烦

c++ - 在 C : How to properly write some sort of "delete/dispose" function? 中使用 C++ 类

c++ - vector 存储限制的 vector - 出现 "Microsoft C++ exception: std::bad_alloc at memory location 0x0031650C."错误

android - "public void onDestroy()"和 "protected void onDestroy()"之间的区别?

java - Junit 用于无效验证方法

c++ - 在 C++ 中找到最小值(双)

c++ - 字符串文字匹配 bool 重载而不是 std::string

HTML/CSS : YouTube iframe as background with controls usable and button overlay

Jquery .change() 函数在本地主机上不起作用

python - 如何删除 python - mechanize 中的控件?