C / C ++中的#error如何工作? [英] How does #error in C/C++ work?

查看:81
本文介绍了C / C ++中的#error如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从#猜测它只是一个编译时实用程序。如何在C / C ++程序中使用它?

I am guessing from # that it is only a compile-time utility. How can it be used in C/C++ programs?

在Internet上找不到太多有关它的信息。任何链接都将有所帮助。

Did not find much about it on the internet. Any links would be helpful.

推荐答案

它会使编译器(或预处理器)输出错误消息。在C ++中,它还会使翻译单元格式错误(即,导致编译失败)。

It causes the compiler (or preprocessor) to output the error message. In C++, it also renders the translation unit ill-formed (i.e., it causes compilation to fail).

如果您可以定义多个宏,并且想要确保仅定义了它们的某些组合,如果定义了无效的组合,则可以使用 #error 导致编译失败。

If you have several macros that could be defined and you want to be sure that only certain combinations of them are defined, you can use #error to cause compilation to fail if an invalid combination is defined.

如果您要确保某些代码块从不编译(无论出于何种原因),它也很有用。

It can also be useful if you want to be sure that some block of code is never compiled (for whatever reason).

这篇关于C / C ++中的#error如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆