Another #error message usage code example
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: Showing the message error and the program stop execution when a condition is met
To show: Another C program example on how to use the #error message
// Another #error directive example...
#include <stdio.h>
#include <stdlib.h>
#if MyChar != 'X'
#error The MyChar character is not 'X'
#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(6) : fatal error C1189: #error : The MyChar character is not 'X'
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 ==========