簡體   English   中英

警告:控制到達非void函數的結尾(c ++)

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

我得到這個錯誤,無法解決,我還是noob,如果有人可以幫助我,我會感謝你這個代碼來自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語句,包括05 但是,如果sort_order為負數或大於5 ,則代碼將在沒有return語句的情況下到達函數的末尾; 這就是編譯器發出警告的原因。

請注意,由於代碼的其他部分存在約束, sort_order可能無法設置為負數或大於5的數字。 但是,編譯器不知道任何一個,所以它認為sort_order可以有任何值。

要解決此問題,請在末尾添加無條件return語句。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM