C中的#error指令有什么用? [英] What is the use of the #error directive in C?

查看:82
本文介绍了C中的#error指令有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C中的 #error 指令是什么?它的用途是什么?

What is the #error directive in C? What is the use of it?

推荐答案

这是一个预处理程序指令,例如,当您期望以下几种可能的一种时使用 -D 符号需要定义,但没有定义。

It's a preprocessor directive that is used (for example) when you expect one of several possible -D symbols to be defined, but none is.

#if defined(BUILD_TYPE_NORMAL)
# define DEBUG(x) do {;} while (0) /* paranoid-style null code */
#elif defined(BUILD_TYPE_DEBUG)
# define DEBUG(x) _debug_trace x /* e.g. DEBUG((_debug_trace args)) */
#else
# error "Please specify build type in the Makefile"
#endif

当预处理程序命中 #error 指令时,它将把字符串报告为错误消息并停止编译;错误消息的确切外观取决于编译器。

When the preprocessor hits the #error directive, it will report the string as an error message and halt compilation; what exactly the error message looks like depends on the compiler.

这篇关于C中的#error指令有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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