“警告:控制达到非无效功能的结束”但实际上该函数被声明为int并返回一个int [英] "warning: control reaches end of non-void function" but actually the function is declared as int and return an int

查看:151
本文介绍了“警告:控制达到非无效功能的结束”但实际上该函数被声明为int并返回一个int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



  int firstHeapArray(IntHeapArray h){
if(!emptyHeapArray(h) )
return h.array [0];
}

它被声明为int,并且这是IntHeapArray结构:

  typedef struct intHeapArray {
int * array;
int size;
} IntHeapArray;

你能说我为什么在编译时得到这个警告吗?

  heap-test.c:在函数'firstHeapArray'中:
heap.h:31:1:warning:控制到达非void函数结束

非常感谢。

解决方案

错误消息指出你有一个方法不是 void return,但是你到达最后而不返回一个值。您需要返回一个有效的int值。



问题出在这里:

  int firstHeapArray(IntHeapArray h){
if(!emptyHeapArray(h))
return h.array [0];

//如果emptyHeapArray(h)为true,则您到达此处...

//您需要返回SOMETHING以删除警告
return 0 ;
}


I have this function:

int firstHeapArray (IntHeapArray h) {
    if(!emptyHeapArray(h))
        return h.array[0];
}

It's declared as int, and this is the IntHeapArray struct:

typedef struct intHeapArray {
    int *array;
    int size;
} IntHeapArray;

Can you say why I get this warning while compiling?

heap-test.c: In function ‘firstHeapArray’:
heap.h:31:1: warning: control reaches end of non-void function

Thank you very much.

解决方案

The error message is stating that you have a method that is not a void return, but you're reaching the end without returning a value. You need to return a valid int value.

The problem is here:

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;
}

这篇关于“警告:控制达到非无效功能的结束”但实际上该函数被声明为int并返回一个int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆