警告:fopen() 调用
你好,我正在 Linux 下使用 stdlib 进行编程。
gcc 对以下代码行发出以下警告,知道为什么吗?
FILE *fd;
if ( fd = fopen( filename, "rw" )== NULL )
{
警告是:
warning: assignment makes pointer from integer without a cast.
这是怎么发生的,根据 stdlib 文档,fopen 的返回类型是 FILE*。那么为什么仍然有警告?知道吗?
- 提前致谢 -
hi I'm programming with stdlib under linux.
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 )
{
and the warning is:
warning: assignment makes pointer from integer without a cast.
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?
--Thanks In Advance--
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试
否则
fd
将采用值 0 或 1,并且fopen
返回的FILE *
本身将丢失。因此,如果没有这些括号,比较结果将存储在fd
中,而不是存储在FILE *
本身中。Try
Otherwise
fd
will take the value 0 or 1 and theFILE *
itself returned byfopen
will be lost. So without those parentheses the result of the comparison will be stored infd
instead of theFILE *
itself.您实质上是将
fd
指定为fopen(filename, "rw") == NULL
,因为条件表达式是一个整数(0 或 1),您正在指定一个来自整数的指针。按照 @cnicutar 的答案进行修复You are essentially assigning
fd
to befopen(filename, "rw") == NULL
, as a conditional expression is an integer (0 or 1), you are assigning a pointer from an integer. follow @cnicutar's answer for the fix只需复制此代码即可工作......
你只是忘了把 () 放在 "fd = fopen( filename, "rw" )" 周围
just copy this code it will work....
you just forget to put () arround "fd = fopen( filename, "rw" )"