Euphoria-ifdef-statement

提供:Dev Guides
移動先:案内検索

ifdef …​ elsifdef …​ elsedef …​ endifdefステートメント

ifdefステートメント

*ifdef* ステートメントは、実行時ではなく解析時に実行されます。 これにより、プログラムの動作方法を非常に効率的に変更できます。

ifdefステートメントは解析時に機能するため、ランタイム値をチェックすることはできません。代わりに、解析時に特別な定義を設定または設定解除できます。

構文

_ifdef_ステートメントの構文は次のとおりです-

ifdef macro then
   -- Statements will execute if the macro is defined.
end if

ブール式の評価がtrueの場合、ifステートメント内のコードブロックが実行されます。 そうでない場合は、ifdefステートメントの終了後の最初のコードセットが実行されます。

_ifdef_は、 with define キーワードを使用して定義されたマクロをチェックします。 WIN32_CONSOLE、WIN32、またはLINUXなどのマクロが多数定義されています。 次のように独自のマクロを定義できます-

with define    MY_WORD    -- defines

次のように、すでに定義されている単語の定義を解除できます-

without define OTHER_WORD -- undefines

#!/home/euphoria-4.0b2/bin/eui

with define DEBUG

integer a = 10
integer b = 20

ifdef DEBUG then
   puts(1, "Hello, I am a debug message one\n")
end ifdef

if (a + b) < 40 then
   printf(1, "%s\n", {"This is true if statement!"})
end if

if (a + b) > 40 then
   printf(1, "%s\n", {"This is not true if statement!"})
end if

これは、次の結果を生成します-

Hello, I am a debug message one
This is true if statement!

_ifdef …​ elsedef_ステートメント

指定されたマクロが定義されている場合は1つのアクションを実行できます。指定されたマクロが定義されていない場合は別のアクションを実行できます。

構文

_ifdef …​ elsedef_ステートメントの構文は次のとおりです-

ifdef macro then
   -- Statements will execute if the macro is defined.
elsedef
   -- Statements will execute if the macro is not defined.
end if

#!/home/euphoria-4.0b2/bin/eui

ifdef WIN32 then
   puts(1, "This is windows 32 platform\n")
elsedef
   puts(1, "This is not windows 32 platform\n")
end ifdef

このプログラムをLinuxマシンで実行すると、次の結果が生成されます-

This is not windows 32 platform

_ifdef …​ elsifdef_ステートメント

*ifdef ... elsifdef* ステートメントを使用して、複数のマクロをチェックできます。

構文

_ifdef …​ elsifdef_ステートメントの構文は次のとおりです-

ifdef macro1 then
   -- Statements will execute if the macro1 is defined.
elsifdef macro2 then
   -- Statements will execute if the macro2 is defined.
elsifdef macro3 then
   -- Statements will execute if the macro3 is defined.
   .......................
elsedef
   -- Statements will execute if the macro is not defined.
end if

#!/home/euphoria-4.0b2/bin/eui

ifdef WIN32 then
   puts(1, "This is windows 32 platform\n")
elsifdef LINUX then
   puts(1, "This is LINUX platform\n")
elsedef
   puts(1, "This is neither Unix nor Windows\n")
end ifdef

このプログラムをLinuxマシンで実行すると、次の結果が生成されます-

This is LINUX platform

上記のすべてのステートメントには、さまざまな状況に基づいた柔軟性と使いやすさを提供するさまざまな形式があります。