Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

The #error directive is a standard C preprocessor directive that instructs the implementation to produce a diagnostic message containing a specified sequence of preprocessor tokens. While the C standard strictly mandates only the generation of this diagnostic message, encountering this directive conventionally prevents the successful translation of the program.

Syntax


# error pp-tokens(opt)
  • #: The preprocessing operator. It must be the first non-whitespace character on the logical source line.
  • error: The identifier specifying the directive. Because # and error are separate preprocessing tokens, they may be separated by whitespace (e.g., # error is perfectly valid).
  • pp-tokens: An optional sequence of preprocessor tokens that constitute the message. The sequence is terminated by a newline character.

Mechanics and Behavior

Tokenization and String Literals The message following the error identifier does not need to be enclosed in double quotes. The preprocessor consumes all characters up to the next newline as a sequence of raw preprocessor tokens. If string literals ("...") are used, the quotes are treated as part of the token sequence and are preserved in the diagnostic output.
/* Emits diagnostic: Fatal error: Architecture unsupported */
#error Fatal error: Architecture unsupported

/* Emits diagnostic: "Fatal error: Architecture unsupported" */

# error "Fatal error: Architecture unsupported"
Macro Expansion The preprocessor does not perform macro expansion on the pp-tokens provided to the #error directive. The literal names of the tokens are emitted in the diagnostic message, regardless of whether they are defined as macros elsewhere in the translation unit.
#define MAX_LIMIT 100
#error The limit is MAX_LIMIT
/* The diagnostic message will literally read "The limit is MAX_LIMIT", not "The limit is 100" */
Standard Compliance and Translation According to the ISO/IEC 9899 C Standard (§6.10.5), a conforming implementation must produce a diagnostic message that includes the specified preprocessor tokens. The standard does not specify the destination of this diagnostic message (such as standard output, standard error, or a log file); the routing of the message is entirely implementation-defined. Furthermore, while the directive is intended to indicate a fatal translation error, the standard does not strictly mandate that the compiler immediately halt and bypass all subsequent translation phases. A compiler may theoretically continue parsing to report multiple diagnostics, though the presence of the #error diagnostic ensures the translation process will ultimately fail to produce a valid executable.
Master C with Deep Grasping Methodology!Learn More