â»ãifãæãæããã¨ããã®ã¯ãã©ããã®æ¡ä»¶å¼ãçã¨è©ä¾¡ãããå ´åã¯ãã以éã®æ¡ä»¶å¼ãè©ä¾¡ããã«ãifãæã®æ¬¡ã¸é²ãã¨ãããã¨ã§ãã 注æããç¹ã¨ãã¦ã¯ãelse ifãã®æ¡ä»¶å¼ã¯ãããããåã«è©ä¾¡ãããå
¨ã¦ã®æ¡ä»¶å¼ãå½ã ã£ãå ´åã®ã¿è©ä¾¡ãããã¨ãããã¨ã§ããä¸è¨ã®ãµã³ãã«ã®ãããªå ´åã§ãã¨ãããããã®æ¡ä»¶å¼ã ããè¦ãã°ã©ã¡ãã®æ¡ä»¶å¼ãçã¨ãªãã¾ããã2çªç®ã®æ¡ä»¶å¼ã¯1çªç®ã®æ¡ä»¶å¼ãå½ã ã£ãå ´åã®ã¿è©ä¾¡ããã¾ãã ã§ã¯ç°¡åãªãµã³ãã«ããã°ã©ã ãä½æãã¦è©¦ãã¦ã¿ã¾ãã ãifãæã§ã¯åç¬ã®æ¡ä»¶åå²ã ãã§ã¯ãªãè¤æ°ã®æ¡ä»¶åå²ã使ã£ã¦å¦çãåãããã¨ãåºæ¥ã¾ããããã«ã¯ãif .. else if .. elseãæã使ç¨ãã¾ããæ¸å¼ã¯æ¬¡ã®éãã§ãã
ãelse ifãã¯å¿
è¦ãªæ°ã ãè¨è¿°ãããã¨ãåºæ¥ã¾ããã¾ãå
¨ã¦ã®æ¡ä»¶å¼ãå½ã ã£ãå ´åã«å®è¡ããå¦çã¨ãã¦ãelseãã®æ¬¡ã®ãããã¯å
ã«å¦çãè¨è¿°ã§ãã¾ãããelseãã®é¨åã¯å¿
è¦ç¡ããã°è¨è¿°ããªãã¦ãæ§ãã¾ããã 「else if」は必要な数だけ記述することが出来ます。また全ての条件式が偽だった場合に実行する処理として「else」の次のブロック内に処理を記述できます。「else」の部分は必要無ければ記述しなくても構いません。 #ifã#elifã#elseãããã³ #endif ãã£ã¬ã¯ãã£ã (C/c + +)ãã以å¤ã®å ´åã¯ãã¨ã©ã¼ã¡ãã»ã¼ã¸ãçæããã¾ããæ¡ä»¶ä»ãã³ã³ãã¤ã« ãã£ã¬ã¯ãã£ããã¤ã³ã¯ã«ã¼ã ãã¡ã¤ã«ã«å«ã¾ãã¦ããå ´åãåãæ¡ä»¶ãæºããå¿
è¦ãããã¾ããã¤ã¾ããã¤ã³ã¯ã«ã¼ã ãã¡ã¤ã«ã®çµããã«å¯¾ã«ãªãæ¡ä»¶ä»ãã³ã³ãã¤ã« ãã£ã¬ã¯ãã£ããå¿
è¦ã§ããWhen conditional-compilation directives are contained in include files, they must satisfy the same conditions: There must be no unmatched conditional-compilation directives at the end of the include file.Macro replacement is done within the part of the line that follows an ããªããã»ããµã¯ãæå®ãããããããã®The preprocessor selects one of the given occurrences of ããªããã»ããµã«ãã£ã¦é¸æãããããã¹ã ãããã¯ã ããã³ã³ãã¤ã«ããã¾ããOnly text blocks selected by the preprocessor are compiled.ããªããã»ããµã¯ãtrue (0 以å¤) ã®å®æ°å¼ãè¦ã¤ããã¾ã§ãå It selects all text (including other preprocessor directives beginning with å¼ã«ã¯æ´æ°åãæå®ããå¿
è¦ããããæ´æ°å®æ°ãæåå®æ°ãããã³Expressions must have integral type and can include only integer constants, character constants, and the ã¿ã¼ã²ããç°å¢ã¯ãæ´æ°ã®ãã¹ã¦ã®ç¯å²ã表ããã¨ãã§ããªãå¯è½æ§ãããã¾ããThe target environment may be unable to represent all ranges of integers.ãã©ã³ã¹ã¬ã¼ã¿ã¼ã¯ãã¿ã¼ã²ããç°å¢ã¨ã¯å¥ã®ã³ã¼ãå¤ã®ã»ããã«æåå®æ°ã翻訳ã§ãã¾ããThe translator can translate character constants to a set of code values different from the set for the target environment.ã¿ã¼ã²ããç°å¢ã®ããããã£ã確èªããã«ã¯ããã®ç°å¢ç¨ã«ãã«ããããã¢ããªã使ç¨ãã¦ãå¶éã®å¤ã確èªãTo determine the properties of the target environment, use an app built for that environment to check the values of the å¼ã¯ç°å¢ã«å¯¾ãã¦ã¯ã¨ãªãå®è¡ãããã¨ã¯ã§ãã¾ãããã¾ãã対象ã®ã³ã³ãã¥ã¼ã¿ã¼ã§å®è£
ã®è©³ç´°ããåé¢ãããç¶æ
ãç¶æããå¿
è¦ãããã¾ããThe expression must not query the environment, and must remain insulated from implementation details on the target computer.This constant expression is considered true (nonzero) if the ãã以å¤ã®å ´åãæ¡ä»¶ã¯ False (0) ã§ãã空ã®ããã¹ãã¨ãã¦å®ç¾©ãããèå¥åã¯ãå®ç¾©ããã¦ããã¨è¦ãªããã¾ããAn identifier defined as empty text is considered defined.ã©ã¡ãã®èå¥åãå®ç¾©ããã¦ããªãå ´åã次ã®ä¾ã®æ¡ä»¶ä»ãã³ã³ãã¤ã« ã¹ãã¼ãã¡ã³ãã¯ãThe conditional compilation statements in the following example assume a previously defined symbolic constant named æ¡ä»¶ä»ãã³ã³ãã¤ã«ã®ä¸è¬çãªç¨éã¯ãåããããã¼ ãã¡ã¤ã«ã®å¤éã¤ã³ã¯ã«ã¼ããé²ããã¨ã§ããA common use for conditional compilation is to prevent multiple inclusions of the same header file.C++ ã§ã¯ãå¤ãã®å ´åãã¯ã©ã¹ããããã¼ãã¡ã¤ã«ã§å®ç¾©ããã¦ããã®ã§ã次ã®ãããªã³ã³ã¹ãã©ã¯ãã使ç¨ãã¦è¤æ°ã®å®ç¾©ãé²ããã¨ãã§ãã¾ããIn C++, where classes are often defined in header files, constructs like this one can be used to prevent multiple definitions:The preceding code checks to see if the symbolic constant ãã®å ´åããã¡ã¤ã«ã¯æ¢ã«å«ã¾ãã¦ãããåå¦çã¯å¿
è¦ããã¾ãããIf so, the file has already been included and doesn't need reprocessing.å®ç¾©ããã¦ããªãå ´åãEXAMPLE.H ãå¦çããã¦ããããã¹ã¦ã®ãã¼ã¸ ãã£ã¼ãããã¯ã表示 #if、#elif、#else、および #endif ディレクティブ (C/c + +) #if, #elif, #else, and #endif directives (C/C++) 08/29/2019 この記事の内容 #Ifディレクティブは、 #elif、 #else、および #endifディレクティブを使用して、ソースファイルの一部のコンパイルを制御します。 ここではC言語の基本構文 if 〜 else文を紹介します。 if 〜 else文 if 〜 else文は、条件式を満たす「真(true)」の場合、条件を満たさない「偽(false)」の場合の両方で何かしらの処理を行う場合に利用します。 ã³ã³ãã¤ã«ãçµããã¾ããããtest5-1ãã¨å
¥åãã¦å®è¡ãã¾ãã if文は、if、else, else if で構成されます。ifだけあれば、if文になります。 condition が真のとき、A の命令が実行されます。 ifだけあれば、if文になります。 else ifは、1つ以上記述できます。省略可能です。 elseは、1つのみ記述できます。省略可能です。elseのブロック{ }の処理は、どの条件も合致しなかったときに実行されます。 if文のサンプルです。 åå¿è
ï½ä¸ç´è
ã®æ¹ã対象ã¨ããããã°ã©ãã³ã°æ¹æ³ãéçºç°å¢ã®æ§ç¯ã®è§£èª¬ãè¡ããµã¤ãã®éå¶ãè¡ã£ã¦ãã¾ãã