警告:返回使指针中的整数不带转换[默认情况下启用] 返回NULL;无法在需要返回整数的函数中返回NULL
我想在我的函数中返回NULL,但它不工作,我不明白为什么是这样。下面是我的代码,但我不会发布整个事情,因为我只有return语句的问题。我希望你能够明白。
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
typedef struct {
int* data;
unsigned int len;
} intarr_t;
int intarr_save_binary(intarr_t* ia, const char* filename)
{
if(ia == NULL)
{
return NULL; // problem here, I want to return NULL if intarr_t*ia is null
}
else
{
// remaining code here, but is uncessary
return 0;
}
}
我的最后一个问题是我该如何检查char数组的文件名是否为NULL?
我这样做:
if (filename == NULL)
{
return NULL;
}
那么,返回类型被声明为一个整数。如果它返回一个指向一个整数的指针,那么你可以返回NULL。 – 2014-11-24 01:31:18
我有点困惑,这是否意味着我必须更改我的函数声明? – TakShing 2014-11-24 01:32:45
也值得了解,null实际上是地址0 ... http://c-faq.com/null/macro.html – 2014-11-24 01:33:52