C 警告:声明无效
当尝试使用以下内容编译我的程序时:
gcc -pedantic -Wall -ansi
我收到警告:警告:语句无效
参考这一行:
for(currentDirection; currentDirection <= endDirection; currentDirection++)
任何人都可以帮我解决这个问题吗?
When trying to compile my prgram with:
gcc -pedantic -Wall -ansi
I get the warning: warning: statement with no effect
Referring to this line:
for(currentDirection; currentDirection <= endDirection; currentDirection++)
Can anyone help me with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
currentDirection;
不执行任何操作。将您的行替换为
Or,以防您忘记初始化变量:
currentDirection;
does nothing.Replace your line with
Or, in case you just forgot to initialize the variable:
第一条语句应该有一个赋值,但在本例中没有发生这种情况,这也是警告的原因。确保为
currentDirection
分配了一个有效值,否则它可能会产生垃圾,并可能在以后导致问题。这类似于所说的——
First statement should have an assignment, which is not happening in this case and is the reason for the warning. Make sure
currentDirection
is assigned to a valid value or it might have garbage and might later cause issues.It is similar to when said -
根据我的经验,当您执行以下操作时,就会出现此问题:
当您声明循环并且已经初始化变量时,x 您不需要再次声明它。
所以要么这样做:
要么
In my experience this issue comes up when you do somthing along the lines of
When you are declaring your loop and you already initialize your variable, x you don't need to declare it a second time.
So either do:
Or