user-0 提问: vs2013中使用#error不能正常编译

回复:
user: user-1
content: 上联：说你行你就行不行也行， 下联：说不行就不行行也不行。 横批：不服不行

user: user-2
content: 编译器读到 #error 就会报错。  就是人为故意产生错误。

user: user-1
content: 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__ )

user: user-3
content: #error 就是表示当编译器看到这一行的时候，保证编译器报错。 比如，你需要你的头文件被 .cpp 文件包含，而不是被 .c 文件包含。 那么就需要这样 #ifndef __cplusplus #error error message. #endif  你可以看看 atlbase.h 中的。atlbase.h 要求用 C++ 编译。

user: user-4
content: 你是写C还是cpp呢，你到底是C语言程序还是C++

user: user-0
content: 引用 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这个指令的作用.

user: user-0
content: 引用 3 楼 Saleayas 的回复:#error 就是表示当编译器看到这一行的时候，保证编译器报错。 比如，你需要你的头文件被 .cpp 文件包含，而不是被 .c 文件包含。 那么就需要这样 #ifndef __cplusplus #error error message. #endif  你可以看看 atlbase.h 中的。atlbase.h 要求用 C++ 编译。也就是说，一旦用了#error就不能编译是吧？

user: user-0
content: 引用 2 楼 www4206 的回复:你是写C还是cpp呢，你到底是C语言程序还是C++ 是C