#error是干什么的

winner8080 2007-04-16 04:19:24
今天考到这个了,
结果一点都不知道
...全文
333 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
lilili5950 2007-04-17
  • 打赏
  • 举报
回复
明显就是嘛,呵呵:)
winner8080 2007-04-17
  • 打赏
  • 举报
回复
我好像有点明白了.
用#error是不是就是让编译器报这个错啊
winner8080 2007-04-17
  • 打赏
  • 举报
回复
楼主,我把
#ifndef WIN32
#error "只能在WIN32下编译"
#end
放进去怎么编译不过,报错再error这行error directive "只能在WIN32下编译"
ayw215 2007-04-17
  • 打赏
  • 举报
回复
学习
WizardLucien 2007-04-16
  • 打赏
  • 举报
回复
例如,我如果希望这段代码只在WIN32下编译。那就可以这样写:
#ifndef WIN32
#error "只能在WIN32下编译"
#end
WIN32下一般都会定义WIN32这个宏,在别的平台下,由于没有这个宏,#error就会起作用。导致编译器遇到一个错误并输出后面的文字,然后终止编译。 :)
guanwl 2007-04-16
  • 打赏
  • 举报
回复
楼主难道没有遭遇过编译错误吗?

用#error就可以定义一个自己的编译错误出来.
sunmc 2007-04-16
  • 打赏
  • 举报
回复
MSDN:

The #error Directive
Error directives produce compiler-time error messages.

Syntax

#error token-string

The error messages include the argument token-string and are subject to macro expansion. These directives are most useful for detecting programmer inconsistencies and violation of constraints during preprocessing. The following example demonstrates error processing during preprocessing:

#if !defined(__cplusplus)
#error C++ compiler required.
#endif

When #error directives are encountered, compilation terminates.
winner8080 2007-04-16
  • 打赏
  • 举报
回复
可以详细的说说吗
WizardLucien 2007-04-16
  • 打赏
  • 举报
回复
用来在编译时产生一个错误的。 :)

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧