当 0 作为参数传递时,GCC 可以发出警告吗?
有人告诉我,您可以在代码中添加一些特殊指令,以使 GCC 在检测到 0 作为参数传递时(这意味着在编译时可能)发出警告。
我已经找过了,但没能找到。这是真的吗?
I have been told that you could add some special instruction to your code to make GCC issue a warning when it detects that 0 is being passed as an argument (which means, when it is possible at compile-time).
I have looked for it but haven’t been able to find it. Is this true?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有一个 函数属性 您可以使用它来警告空指针:
I不过,我不知道有任何内置的东西可以检查整数类型是否为 0。
不过,您可能会在 Linux 内核的各种
BUILD_BUG_*
宏中找到适合您需要的内容。它们位于include/linux/kernel.h
中。 (此处交叉引用。)There is a function attribute you can use to warn on null pointers:
I'm not aware of anything built-in to check for 0 for integer types though.
You might find something that suits your need in the various
BUILD_BUG_*
macros from the Linux kernel though. They're ininclude/linux/kernel.h
. (Cross-referenced here.)