警告:fopen()调用 [英] warning: fopen() call

查看:325
本文介绍了警告:fopen()调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Linux下使用stdlib进行编程.

hi I'm programming with stdlib under linux.

gcc针对以下代码行发出以下警告,这是为什么?

The gcc emits the following warning for the following line of code, any idea why is that?

FILE *fd;
if ( fd = fopen( filename, "rw" )== NULL )
{

警告是:

warning: assignment makes pointer from integer without a cast.

这是怎么发生的,根据stdlib文档,fopen的返回类型为FILE *.那么为什么仍然有警告呢?知道吗?

How this can be happen , according to the stdlib documentation the return type of fopen is FILE*. So why there is a warning still there?Any idea?

-预先感谢-

推荐答案

尝试

if ((fd = fopen( filename, "rw")) == NULL)
    ^                           ^ 

否则,fd将取值为0或1,并且fopen返回的FILE *本身将丢失.因此,如果没有这些括号,则比较结果将存储在fd中,而不是在FILE *中.

Otherwise fd will take the value 0 or 1 and the FILE * itself returned by fopen will be lost. So without those parentheses the result of the comparison will be stored in fd instead of the FILE * itself.

这篇关于警告:fopen()调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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