The #error message usage for displaying the error message for the stated condition
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Header file: Standard
Additional library: none/default
Additional project setting: Set project to be compiled as C
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)
Other info: none
To do: Displaying the message error when a condition is fulfilled during the C/C++ compilation
To show: How to use the #error message when a condition is met during the C/C++ compilation, conditional compilation
// The #error directive...
#include <stdio.h>
#if MyVAL != 2
#error MyVAL must be defined to 2
#endif
int main(void)
{
return 0;
}
Output example:
// No output.
You can see the following statements in the output window after the compilation.
1>------ Build started: Project: myaddr, Configuration: Debug Win32 ------
1>Compiling...
1>myaddr.cpp
1>f:\vc2005project\myaddr\myaddr\myaddr.cpp(5) : fatal error C1189: #error : MyVAL must be defined to 2
1>Build log was saved at "file://f:\vc2005project\myaddr\myaddr\Debug\BuildLog.htm"
1>myaddr - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========