警告:控制达到非空隙函数的末端(C )
warning: control reaches end of non-void function (c++)
我得到了这个错误,无法解决,我是菜鸟,如果有人可以帮助我,我会谢谢你此代码来自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;
}
}
}
编译器分析您的代码,并发现将对0
和5
之间的所有sort_order
值执行返回语句,包括。但是,如果sort_order
为负或比5
高,则代码将在没有返回语句的情况下到达函数的末尾;这就是为什么编译器发出警告的原因。
请注意,由于代码其他部分的限制,sort_order
不可能设置为负数或5
上的数字。但是,编译器不知道这一点,因此它认为sort_order
可以具有任何价值。
要解决此问题,请在末尾添加一个无条件的返回语句。
相关文章:
- 控制到达非空函数clang(-Wreturn-type)的末尾
- 我在 C++ 代码中遇到错误警告:控制到达非空函数 [-Wreturn 类型] 的末尾
- 是否可以使用三元切换/控制/谓词成员函数调用?
- 如何使用 qt 中的信号槽控制函数的返回
- 控制使用 while 循环到达非空函数 (c++) 的末尾
- 控制通过类中的成员函数更改成员变量的能力C++
- 错误:控制到达非空函数的末尾 [-Werror=返回类型] } ^
- 访问控制对于已删除的构造函数是否重要?
- HPX 是否提供具有粒度控制的基于任务的并行化迭代函数?
- Windows SDK 控制可用的函数
- 控制可能达到C 中非空隙函数误差的末端
- 如何根据模板参数包是否匹配函数参数来控制模板函数定义?
- 不受控制的循环和函数 C++跳过
- 当我尝试对数组的内容使用函数时,控制台中没有显示任何内容
- 为什么具有私有构造函数的类不阻止从此类继承?如何控制哪些类可以从某个基继承?
- 将数组传递给函数的大小控制
- 仅在我退出应用程序后,使用Cout.write()函数在控制台上打印字符串
- 编译错误:(警告:控制到达非空函数 [-wreturn 类型] 的末尾)
- 从另一个函数控制RenderWindow
- c++中的哪些流函数控制类的输入和输出值的格式