我有这个功能:
int firstHeapArray (IntHeapArray h) {
if(!emptyHeapArray(h))
return h.array[0];
}
它被声明为 int,这是 IntHeapArray 结构:
typedef struct intHeapArray {
int *array;
int size;
} IntHeapArray;
你能说说为什么我在编译时会收到这个警告吗?
heap-test.c: In function ‘firstHeapArray’:
heap.h:31:1: warning: control reaches end of non-void function
非常感谢。
最佳答案
错误消息表明您有一个不是 void
返回值的方法,但您在没有返回值的情况下到达终点。您需要返回一个有效的 int 值。
问题出在这里:
int firstHeapArray (IntHeapArray h) {
if(!emptyHeapArray(h))
return h.array[0];
// If emptyHeapArray(h) is true, you reach here...
// You need to return SOMETHING here to remove the warning
return 0;
}
关于c - "warning: control reaches end of non-void function"但实际上该函数被声明为 int 并返回一个 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10964528/