vs2013中使用#error不能正常编译

time1609 2015-01-28 10:17:54
刚学到这里,但是在VS2013中 使用#error的时候直接就出现红色波浪线,直接报错。后缀名是.c,改成.cpp也不行。直接复制网上的代码也是一样红色的波浪线.
#line 这个指令到是很正常。
...全文
208 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2015-01-30
  • 打赏
  • 举报
回复
上联:说你行你就行不行也行, 下联:说不行就不行行也不行。 横批:不服不行
「已注销」 2015-01-30
  • 打赏
  • 举报
回复
编译器读到 #error 就会报错。 就是人为故意产生错误。
赵4老师 2015-01-29
  • 打赏
  • 举报
回复
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. _________________________________________________________ message #pragma message( messagestring ) Sends a string literal to the standard output without terminating the compilation. A typical use of the message pragma is to display informational messages at compile time. The following code fragment uses the message pragma to display a message during compilation: #if _M_IX86 == 500 #pragma message( "Pentium processor build" ) #endif The messagestring parameter can be a macro that expands to a string literal, and you can concatenate such macros with string literals in any combination. For example, the following statements display the name of the file being compiled and the date and time when the file was last modified: #pragma message( "Compiling " __FILE__ ) #pragma message( "Last modified on " __TIMESTAMP__ )
Saleayas 2015-01-29
  • 打赏
  • 举报
回复
#error 就是表示当编译器看到这一行的时候,保证编译器报错。 比如,你需要你的头文件被 .cpp 文件包含,而不是被 .c 文件包含。 那么就需要这样
#ifndef __cplusplus
#error error message.
#endif
你可以看看 atlbase.h 中的。atlbase.h 要求用 C++ 编译。
砖家的谎言 2015-01-29
  • 打赏
  • 举报
回复
你是写C还是cpp呢,你到底是C语言程序还是C++
time1609 2015-01-29
  • 打赏
  • 举报
回复
引用 4 楼 zhao4zhong1 的回复:
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. _________________________________________________________ message #pragma message( messagestring ) Sends a string literal to the standard output without terminating the compilation. A typical use of the message pragma is to display informational messages at compile time. The following code fragment uses the message pragma to display a message during compilation: #if _M_IX86 == 500 #pragma message( "Pentium processor build" ) #endif The messagestring parameter can be a macro that expands to a string literal, and you can concatenate such macros with string literals in any combination. For example, the following statements display the name of the file being compiled and the date and time when the file was last modified: #pragma message( "Compiling " __FILE__ ) #pragma message( "Last modified on " __TIMESTAMP__ )
是说
引用 4 楼 zhao4zhong1 的回复:
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. _________________________________________________________ message #pragma message( messagestring ) Sends a string literal to the standard output without terminating the compilation. A typical use of the message pragma is to display informational messages at compile time. The following code fragment uses the message pragma to display a message during compilation: #if _M_IX86 == 500 #pragma message( "Pentium processor build" ) #endif The messagestring parameter can be a macro that expands to a string literal, and you can concatenate such macros with string literals in any combination. For example, the following statements display the name of the file being compiled and the date and time when the file was last modified: #pragma message( "Compiling " __FILE__ ) #pragma message( "Last modified on " __TIMESTAMP__ )
好像有点明白了,但还是不太懂#error这个指令的作用.
time1609 2015-01-29
  • 打赏
  • 举报
回复
引用 3 楼 Saleayas 的回复:
#error 就是表示当编译器看到这一行的时候,保证编译器报错。 比如,你需要你的头文件被 .cpp 文件包含,而不是被 .c 文件包含。 那么就需要这样
#ifndef __cplusplus
#error error message.
#endif
你可以看看 atlbase.h 中的。atlbase.h 要求用 C++ 编译。
也就是说,一旦用了#error就不能编译是吧?
time1609 2015-01-29
  • 打赏
  • 举报
回复
引用 2 楼 www4206 的回复:
你是写C还是cpp呢,你到底是C语言程序还是C++
是C

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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