#error Directive

These two directives force the compiler to emit an error, with the text of the directive argument being the error message. For example,

#error "Out of Cheese Error"

... will force the compiler to print "Out of Cheese Error" at the line where the directive appears during compilation. These are used primarily for debugging purposes. They can also be used together with conditional compilation to halt compilation under certain conditions. For example,

#ifndef WINDOWS
#error "This program can only be compiled for Windows"
#endif

...could be used to ensure that a Windows-specific program could not be compiled for other operating systems by mistake.


Contents Previous Next