好朋友。我发现fopen的返回值通过以下两种方式不同:
1.
int main()
{
FILE* fp_file = NULL;
fp_file = fopen(file_path, "wb");
if(NULL == fp_file)
return RET_NULL_POINT;
else
return RET_OK;
}
2.
int _open_file(const char* ps_file_path, const char* ps_open_mode, FILE* fp_arg)
{
if(NULL == ps_file_path || NULL == ps_open_mode)
{ return RET_INV_ARG;}
fp_arg = fopen(ps_file_path, ps_open_mode);
if(NULL == fp_arg)
{ return RET_NULL_POINT;}
else
{ return RET_OK;}// fp_arg is NULL after fopen, but it return RET_OK, why?
}
int main()
{
FILE* fp_file = NULL;
int i4_ret = 0;
i4_ret = _open_file((const char*)file_path, "wb", fp_file);
if(RET_OK != i4_ret)
{// do sth NG}
else
{// do sth OK}
......//NULL_POINT exception will be caused at some place below.
}
2) 的 file_path 与 1) 相同。1)的结果是返回RET_OK,2)的i4_ret的结果是RET_OK,但是fp_file是NULL。我想知道为什么 1) 的 fp_file 是正确的值,但在 2) 中它是 NULL?fopen 的参数在 1) 和 2) 之间没有区别。