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.
式はフォームに単項演算子が含まれている場合があり
defined
identifierまたは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.
#ifdef
identifier#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.
#ifndef
identifier#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.
[編集]例
このコードを実行します
出力:
1: yes 2: yes 3: yes