[英]warnings with c program compiling :assignment makes pointer from integer without a cast [enabled by default]
when I compiling the a program named Online_ana.c (by running a makefile) with following line: 当我通过以下行编译名为Online_ana.c的程序(通过运行makefile)时:
if ((fifoFile = open((FIFO1!=NULL) ? FIFO1 : "fifo1", O_RDONLY)) == -1)
encountered with such warnings: 遇到此类警告:
Online_ana.c:54:17: warning: assignment makes pointer from integer without a cast [enabled by default]
Online_ana.c:54:17:警告:赋值使指针从整数开始而没有强制转换[默认启用]
whats is wrong with that? 这是怎么了? Hope that someone can help me.
希望有人能帮助我。 Thanks in advance!!
提前致谢!!
There's a couple things wrong with this. 这有几处错误。
1)You're assigning an integer value to a pointer. 1)您正在为指针分配一个整数值。 This isn't always wrong, but it is suspicious.
这并不总是错误的,但令人怀疑。 It usually means a bug, but there are some situations where its ok.
它通常表示错误,但在某些情况下还可以。 THat's why the compiler spits out a warning rather than an error.
这就是为什么编译器会发出警告而不是错误的原因。 You should assure that you mean it.
您应该确保您是认真的。
2)Like @Barmar said, open returns an integer (a file handle) not a FILE*. 2)就像@Barmar所说,open返回一个整数(文件句柄)而不是FILE *。 If you're assigning one to the other its wrong.
如果将一个分配给另一个,那就错了。
3)Slightly unrelated, but assigning and comparing in an if like that is almost always a bad idea. 3)有点无关,但是在这样的情况下进行分配和比较几乎总是一个坏主意。 Its too easy to accidentally type = somewhere you meant == and cause bugs.
它很容易在不想要的地方键入= =并导致错误。 It should be avoided, use 1 line for assignment and 1 for comparison.
应避免使用,使用1行进行分配,使用1行进行比较。 I know old school C style is to use a single line, but these days its considered a bad idea.
我知道老派的C风格是使用单行,但是如今,这被认为是一个坏主意。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.