Other Preprocessor Commands
Beyond#define, #include, and #ifdef, the C preprocessor provides several other useful directives.
#pragma
#pragma provides implementation-specific (compiler-specific) instructions. The most widely-used are:
#pragma once — modern include guard (prevents a header from being included multiple times):
#pragma warning (MSVC) — suppress or enable specific warnings:
#pragma comment (MSVC) — link a library:
#pragma directives are not portable — they vary between compilers. Code using them may not compile on a different compiler.#error
Forces a compile-time error with a custom message. Useful for catching configuration mistakes:
MAX_SIZE is not defined, compilation stops immediately with the specified message.
#line
Changes the line number (and optionally the filename) reported by the compiler in error messages:
Predefined Macros
The C standard defines several macros that are automatically available in every program:
Example: