名前空間
変種
操作

Conditional inclusion

提供: cppreference.com

 
 
C + +言語
一般的なトピック
Original:
General topics
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
フロー制御
Original:
Flow control
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
条件付き実行文
Original:
Conditional execution statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
繰り返し文
Original:
Iteration statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
文をジャンプします
Original:
Jump statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
機能します
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
関数の宣言
ラムダ関数の宣言
関数テンプレート
の歴史。インライン指定
例外仕様 (廃止予定)
noexcept指定子 (C++11)
例外
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
名前空間
Original:
Namespaces
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
タイプ
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
decltype specifier (C++11)
指定子
Original:
Specifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
CV指定
貯蔵期間指定
constexprの指定子 (C++11)
自動指定 (C++11)
alignas指定子 (C++11)
初期化
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
リテラル
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
代替表現
ユーティリティ
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
タイプ
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
typedef declaration
型の別名宣言 (C++11)
属性 (C++11)
キャストします
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
暗黙の型変換
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
Cスタイルキャストと機能
メモリの割り当て
Original:
Memory allocation
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
クラス
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
クラス固有の機能特性
Original:
Class-specific function properties
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
明示 (C++11)
静的
特殊なメンバ関数
Original:
Special member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
テンプレート
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
クラステンプレート
関数テンプレート
テンプレートの特殊化
パラメーターパック (C++11)
その他
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
インラインアセンブリ
 
 
プリプロセッサは、ソースファイルの一部の条件付きコンパイルをサポートしています。この動作は#if#else#elif#ifdef#ifndef#endifディレクティブによって制御されます.
Original:
The preprocessor supports conditional compilation of parts of source file. This behavior is controlled by #if, #else, #elif, #ifdef, #ifndef and #endif directives.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目次

[編集] 構文

#if expression
#elif expression
#ifdef expression
#ifndef expression
#else expression
#endif expression

[編集] 説明

条件付きプリブロックは#ifで始まり、#ifdefまたは#ifndef指令、その後必要に応じて#elifディレクティブは、任意の数を含んで、その後必要に応じて、最大で1つの#elseディレクティブが含まれており、#endifディレクティブで終了します。内側のどの条件、前処理ブロックは別々に処理されます.
Original:
The conditional preprocessing block starts with #if, #ifdef or #ifndef directive, then optionally includes any number of #elif directives, then optionally includes at most one #else directive and is terminated with #endif directive. Any inner conditional preprocessing blocks are processed separately.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
#ifの各々は、#elif#else#ifdef#ifndefディレクティブの制御コード·ブロックまで初回#elif#else、任意の内部条件、前処理ブロックに属さない#endifディレクティブ.
Original:
Each of #if, #elif, #else, #ifdef and #ifndef directives control code block until first #elif, #else, #endif directive not belonging to any inner conditional preprocessing blocks.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
#if#ifdef#ifndefディレクティブは、指定した条件をテストします(下記参照)、それが真と評価された場合に、制御されたコードブロックをコンパイルします。その場合には、後続の#else#elifディレクティブは無視されます。指定した条件がfalseと評価された場合、それ以外の場合、制御コード·ブロックはスキップされ、後続の#elseまたは#elifディレクティブが(もしあれば)処理されます。前者の場合には、#elseディレクティブで制御コード·ブロックは無条件にコンパイルされます。条件をチェックし、コンパイルしたり結果に基づいて、制御されたコードブロックをスキップし、後者の場合には、後続の#elif#ifディレクティブを処理します後者の場合には、#elif·ディレクティブは、それが#else指令であるかのように動作します。条件付きプリブロックは#endifディレクティブで終了する.
Original:
#if, #ifdef and #ifndef directives test the specified condition (see below) and if it evaluates to true, compiles the controlled code block. In that case subsequent #else and #elif directives are ignored. Otherwise, if the specified condition evaluates false, the controlled code block is skipped and the subsequent #else or #elif directive (if any) is processed. In the former case, the code block controlled by the #else directive is unconditionally compiled. In the latter case, the #elif directive acts as if it was #if directive: checks for condition, compiles or skips the controlled code block based on the result, and in the latter case processes subsequent #elif and #else directives. The conditional preprocessing block is terminated by #endif directive.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 条件の評価

[編集] #if, #elif

expressionリテラルディレクティブを使用して定義された唯一 #defineと識別子を使用して、定数式です。リテラルではありません任意の識別子は、 #defineディレクティブを使用して定義された非、 0と評価された.
Original:
The expression is a constant expression, using only リテラル and identifiers, defined using #define directive. Any identifier, which is not literal, non defined using #define directive, evaluates to 0.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
式はフォームに単項演算子が含まれている場合がありdefinedidentifierまたはdefined (identifier)1identifier指令と'そうでなければ0を使用して定義されている場合 #defineを返している。 expressionがゼロ以外の値に評価された場合、制御コード·ブロックが含まれ、それ以外の場合はスキップされます。任意に使用される識別子が定数でない場合、それは0に置き換えられます.
Original:
The expression may contain unary operators in form defined identifier or defined (identifier) which return 1 if the identifier was defined using #define directive and 0 otherwise. If the expression evaluates to nonzero value, the controlled code block is included and skipped otherwise. If any used identifier is not a constant, it is replaced with 0.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] #ifdef, #ifndef

小切手識別子が #defineディレクティブを使用して定義されている場合.
Original:
Checks if the identifier was defined using #define directive.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
#ifdefidentifier#if defined(identifier)と基本的に同等です.
Original:
#ifdef identifier is essentially equivalent to #if defined( identifier).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
#ifndefidentifier#if !defined(identifier)と基本的に同等です.
Original:
#ifndef identifier is essentially equivalent to #if !defined( identifier).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集]

#define ABCD 2
#include <iostream>
 
int main()
{
 
#ifdef ABCD
    std::cout << "1: yes\n";
#else
    std::cout << "1: no\n";
#endif
 
#ifndef ABCD
    std::cout << "2: no1\n";
#elif ABCD == 2
    std::cout << "2: yes\n";
#else
    std::cout << "2: no2\n";
#endif
 
#if !defined(DCBA) && (ABCD < 2*4-3)
    std::cout << "3: yes\n";
#endif
}

Output:

1: yes
2: yes
3: yes