警告:控制达到非空隙函数的末端(C )

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

本文关键字:函数 控制 警告      更新时间:2023-10-16

我得到了这个错误,无法解决,我是菜鸟,如果有人可以帮助我,我会谢谢你此代码来自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值执行返回语句,包括。但是,如果sort_order为负或比5高,则代码将在没有返回语句的情况下到达函数的末尾;这就是为什么编译器发出警告的原因。

请注意,由于代码其他部分的限制,sort_order不可能设置为负数或5上的数字。但是,编译器不知道这一点,因此它认为sort_order可以具有任何价值。

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