Conditional inclusion
提供: cppreference.com
< cpp | preprocessor
|
|
このページは、Google 翻訳を使って英語版から機械翻訳されました。
翻訳には誤りや奇妙な言い回しがあるかもしれません。文章の上にポインタをおくと、元の文章が見れます。誤りを修正して翻訳を改善する手助けをしてください。翻訳についての説明は、ここをクリックしてください。 |
プリプロセッサは、ソースファイルの一部の条件付きコンパイルをサポートしています。この動作は
#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.
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.
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.
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.
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.
You can help to correct and verify the translation. Click here for instructions.
式はフォームに単項演算子が含まれている場合があり
definedidentifierまたはdefined (identifier)1がidentifier指令と'そうでなければ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.
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.
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.
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.
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 }
出力:
1: yes 2: yes 3: yes