简体   繁体   English

c程序编译警告:分配使指针从整数开始而没有强制转换[默认启用]

[英]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.

相关问题 赋值使指针从整数开始而不进行强制转换[默认启用] - assignment makes pointer from integer without cast [enabled by default] 警告:赋值使指针从整数开始而没有强制转换[默认启用] - warning: assignment makes pointer from integer without a cast [enabled by default] "警告:赋值从没有强制转换的指针生成整数 [默认启用]" - Warning : assignment makes integer from pointer without cast [enabled by default] 警告:赋值使指针从整数变为整数而不进行强制转换[默认启用] - warning: assignment makes integer from pointer without a cast [enabled by default] 赋值使指针从整数开始,默认情况下未启用强制转换 - assignment makes pointer from integer without a cast enabled by default 错误分配使指针从整数开始而没有强制转换[默认启用] - Error Assignment makes pointer from integer without a cast [enabled by default] C Linux:警告:赋值使指针从整数变成整数而没有强制转换[默认启用] - C Linux: warning: assignment makes integer from pointer without a cast [enabled by default] C:警告:赋值使得整数指针没有强制转换[默认启用] - C : warning: assignment makes pointer from integer without a cast [enabled by default] C:警告:赋值使指针从整数开始而没有强制转换[默认启用] - C: Warning: assignment makes pointer from integer without a cast [enabled by default] C程序-警告:赋值使指针从整数开始而没有强制转换 - C Program - warning: assignment makes pointer from integer without a cast
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM