修正warning c4786

详细请见http://support.microsoft.com/default.aspx?scid=kb;en-us;167355

另附上VC中默认关闭的warning:

The compiler includes warnings that are off by default. If a warning is off by default, most users would not want to see such warnings for their code. However, some users would be interested to see such output from the compiler.

A warning that is off by default can be enabled in one of several ways:

#pragma warning(default : warning_number )
The warning is enabled at its default level. Documentation for the warning contains the default level of the warning.
#pragma warning( warning_level : warning_number )
The warning is enabled at the specified level ( warning_level).
tabindex="0" keywords="_core_.2f.W.2c_2f.w">/Wall
This compiler option enables all warnings that are off by default.

The following warnings are off by default:

  • tabindex="0" keywords="C4056">C4056
  • tabindex="0" keywords="C4061">C4061
  • tabindex="0" keywords="C4062">C4062
  • tabindex="0" keywords="vcrefCompilerWarning(level3)C4191">C4191
  • tabindex="0" keywords="vcerrCompilerWarningLevel1C4217">C4217
  • tabindex="0" keywords="vchowCompilerWarningLevel1C4242">C4242
  • tabindex="0" keywords="vcerrCompilerWarningLevel4C4254">C4254
  • tabindex="0" keywords="vcerrCompilerWarningLevel4C4255">C4255
  • tabindex="0" keywords="vctbsCompilerWarningLevel1C4263">C4263
  • tabindex="0" keywords="vctbsCompilerWarningLevel1C4264">C4264
  • tabindex="0" keywords="vcerrCompilerWarningLevel3C4265">C4265
  • tabindex="0" keywords="vcerrCompilerWarningLevel1C4287">C4287
  • tabindex="0" keywords="vctbsCompilerWarningLevel4C4289">C4289
  • tabindex="0" keywords="vcerrCompilerWarningLevel1C4296">C4296
  • tabindex="0" keywords="vcerrCompilerWarningLevel2C4302">C4302
  • tabindex="0" keywords="vcerrCompilerWarningLevel4C4339">C4339
  • tabindex="0" keywords="vcerrCompilerWarningLevel4C4347">C4347
  • tabindex="0" keywords="C4514">C4514
  • tabindex="0" keywords="vcerrCompilerWarningLevel1C4529">C4529
  • tabindex="0" keywords="vcerrCompilerWarningLevel1C4545">C4545
  • tabindex="0" keywords="vcerrCompilerWarningLevel1C4546">C4546
  • tabindex="0" keywords="vcerrCompilerWarningLevel1C4547">C4547
  • tabindex="0" keywords="vcerrCompilerWarningLevel1C4548">C4548
  • tabindex="0" keywords="vcerrCompilerWarningLevel1C4549">C4549
  • tabindex="0" keywords="vcerrCompilerWarningLevel4C4536">C4536
  • tabindex="0" keywords="vchowCompilerWarningLevel1C4555">C4555
  • tabindex="0" keywords="vcerrCompilerWarningLevel3C4557">C4557
  • tabindex="0" keywords="vcerrCompilerWarningLevel3C4619">C4619
  • tabindex="0" keywords="vcerrCompilerWarningLevel4C4623">C4623
  • tabindex="0" keywords="vcerrCompilerWarningLevel4C4625">C4625
  • tabindex="0" keywords="vcerrCompilerWarningLevel4C4626">C4626
  • tabindex="0" keywords="vcerrCompilerWarningLevel1C4628">C4628
  • tabindex="0" keywords="vcerrCompilerWarningLevel3C4640">C4640
  • tabindex="0" keywords="vcerrCompilerWarningLevel4C4668">C4668
  • tabindex="0" keywords="vcerrCompilerWarningLevel4C4682">C4682
  • tabindex="0" keywords="vcerrCompilerWarningLevel3C4686">C4686
  • tabindex="0" keywords="C4710">C4710
  • tabindex="0" keywords="C4786">C4786
  • tabindex="0" keywords="vclrfCompilerWarningLevel3C4793">C4793
  • tabindex="0" keywords="vcerrCompilerWarningLevel4C4820">C4820
  • tabindex="0" keywords="vcerrCompilerWarningLevel1C4905">C4905
  • tabindex="0" keywords="vcerrCompilerWarningLevel1C4906">C4906
  • tabindex="0" keywords="vctbsCompilerWarningLevel1C4917">C4917
  • tabindex="0" keywords="vcerrCompilerWarningLevel1C4928">C4928
  • tabindex="0" keywords="vcerrCompilerWarningLevel4C4931">C4931
  • tabindex="0" keywords="vcerrCompilerWarningLevel1C4946">C4946
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 这个警告提示的意思是,有一段代码是无法执行到的,因为在代码的前面已经有一个 return 语句或者是一个无限循环等,导致后面的代码不可能被执行到。 例如,下面的代码: ```c int foo(int x) { if (x < 0) { return 0; } printf("x is positive\n"); return x; } ``` 因为在 if 语句后面有一个 return 语句,所以程序不可能执行到 printf 语句,编译器就会发出警告。 如果你确定这段代码是可达的,可以考虑在前面加上一个断言语句,例如: ```c assert(x >= 0); ``` 这样可以让编译器知道这段代码是可达的,不会发出警告。 ### 回答2: 这个警告意味着在代码中存在无法执行到达的代码。出现这个警告通常是因为在前面的代码逻辑中已经确保了条件得到满足,而后面的代码不会被执行到。 根据给出的信息,看起来是在"shiyan2.c"文件的第68行出现了这个警告。警告的具体原因需要查看代码才能确定是什么原因导致的。 可能的原因有: 1. 前面的代码块中进行了返回或跳转操作,导致后面的代码无法执行到; 2. 循环控制条件错误,导致循环条件一开始就不满足,循环内部代码无法执行; 3. 条件判断语句逻辑错误,导致分支代码始终无法执行到。 为了解决这个警告,需要检查代码逻辑,确保后面的代码不会出现无法到达的情况。可以尝试以下操作: 1. 检查前面的代码块是否存在早期的返回或跳转操作; 2. 检查循环控制条件是否正确,确保循环内部代码会执行; 3. 检查条件判断逻辑是否正确,确保分支代码会被执行到。 最后,建议通过代码审查、重构或调试等方法进一步解决这个问题。 ### 回答3: 在C语言编程中,当我们编写代码时,编译器会对代码进行检查并给出一些警告信息。其中之一是“warning C294: unreachable code”,意思是存在无法到达的代码。 正常情况下,程序会按照从上到下的顺序执行代码。当编译器检测到某一部分代码无论如何都无法被执行到时,就会给出这个警告。 举个例子来说明这个问题。我们假设在代码中有如下的结构: if (condition1){ // 代码块1 } else if (condition2){ // 代码块2 } else { // 代码块3 } 在这个代码块中,只有当condition1为真时,才会执行代码块1。当condition1为假且condition2为真时,才会执行代码块2。当condition1、condition2都为假时,才会执行代码块3。 如果编译器检测到在某个位置,无论如何都无法进入到某一部分代码(例如,condition1和condition2都为真时跳转到代码块3),就会给出这个警告。 这个警告实际上是在提示我们代码中的逻辑存在问题,有可能是因为条件判断写错了、逻辑错误等。因此,我们在阅读这个警告信息时,需要仔细检查代码逻辑,进行相应的修正,以确保代码的正确性和可达性。 总结起来,编译器给出“warning C294: unreachable code”警告意味着在代码中存在无法到达的代码,我们需要仔细检查代码逻辑并进行修正

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值