如何向GCC提示在编译时某行不可达? [英] How to hint to GCC that a line should be unreachable at compile time?
本文介绍了如何向GCC提示在编译时某行不可达?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
编译器通常会提供切换为在代码无法访问时发出警告.我还看到了某些库的宏,这些宏提供了
It's common for compilers to provide a switch to warn when code is unreachable. I've also seen macros for some libraries, that provide assertions for unreachable code.
是否存在某种提示(例如通过编译指示或内置的提示),我可以将其传递给GCC(或与此有关的任何其他编译器),如果确定行预期会在编译期间发出警告或错误真的可以到达吗?
这是一个例子:
if (!conf->devpath) {
conf->devpath = arg;
return 0;
} // pass other opts into fuse
else {
return 1;
}
UNREACHABLE_LINE();
此值的作用是在条件超出预期的不可达线之后检测到该线实际上是可达到的.
The value of this is in detecting, after changes in conditions above the expected unreachable line, that the line is in fact reachable.
推荐答案
gcc 4.5 supports the __builtin_unreachable()
compiler inline, combining this with -Wunreachable-code
might do what you want, but will probably cause spurious warnings
这篇关于如何向GCC提示在编译时某行不可达?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文