Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      Preprocessor

      From cppreference.com
      <cpp
       
       
      C++ language
      General topics
      Preprocessor
      Comments
      Flow control
      Conditional execution statements
      Iteration statements (loops)
      Jump statements
      Functions
      Function declaration
      Lambda function expression
      inline specifier
      Dynamic exception specifications(until C++17*)
      noexcept specifier(C++11)
      Exceptions
      Namespaces
      Types
      Specifiers
      constexpr(C++11)
      consteval(C++20)
      constinit(C++20)
      Storage duration specifiers
      Initialization
      Expressions
      Alternative representations
      Literals
      Boolean -Integer -Floating-point
      Character -String -nullptr(C++11)
      User-defined(C++11)
      Utilities
      Attributes(C++11)
      Types
      typedef declaration
      Type alias declaration(C++11)
      Casts
      Memory allocation
      Classes
      Class-specific function properties
      Special member functions
      Templates
      Miscellaneous
       
       

      The preprocessor is executed attranslation phase 4, before the compilation. The result of preprocessing is a single file which is then passed to the actual compiler.

      Contents

      [edit]Directives

      The preprocessing directives control the behavior of the preprocessor. Each directive occupies one line and has the following format:

      • the# character.
      • a sequence of:
      • a standard-defined directive name (listedbelow) followed by the corresponding arguments, or
      • one or morepreprocessing tokens where the beginning token is not a standard-defined directive name, in this case the directive is conditionally-supported with implementation-defined semantics (e.g. a common non-standard extension is the directive#warning which emits a user-defined message during compilation)(until C++23), or
      • nothing, in this case the directive has no effect.
      • a line break.

      Themodule and import directives are also preprocessing directives.

      (since C++20)

      Preprocessing directives must not come from macro expansion.

      #define EMPTYEMPTY#   include <file.h> // not a preprocessing directive

      [edit]Capabilities

      The preprocessor has the source file translation capabilities:

      • conditionally compile parts of source file (controlled by directive#if,#ifdef,#ifndef,#else,#elif,#elifdef,#elifndef(since C++23), and#endif).
      • replace text macros while possibly concatenating or quoting identifiers (controlled by directives#define and#undef, and operators# and##).
      • include other files (controlled by directive#includeand checked with__has_include(since C++17)).
      • cause anerrororwarning(since C++23) (controlled by directive#error or#warning respectively(since C++23)).

      The following aspects of the preprocessor can be controlled:

      • implementation-defined behavior (controlled by directive#pragmaand operator_Pragma(since C++11)). In addition, some compilers support (to varying degrees) the operator__pragma as anon-standard extension.
      • file name and line information available to the preprocessor (controlled by directive#line).

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      CWG 2001C++98the behavior of using non-standard-defined directives was not clearmade conditionally-supported

      [edit]See also

      C++ documentation forPredefined Macro Symbols
      C++ documentation forMacro Symbol Index
      C documentation forpreprocessor
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/preprocessor&oldid=156005"

      [8]ページ先頭

      ©2009-2025 Movatter.jp