条件付きコンパイル・ディレクティブの例

以下の例は、プリプロセッサーの条件付きコンパイル・ディレクティブをどのようにネスト できるかを示しています。

#if defined(TARGET1)
#   define SIZEOF_INT 16
#   ifdef PHASE2
#      define MAX_PHASE 2
#   else
#      define MAX_PHASE 8
#   endif
#elif defined(TARGET2)
#   define SIZEOF_INT 32
#   define MAX_PHASE 16
#else
#   define SIZEOF_INT 32
#   define MAX_PHASE 32
#endif

以下のプログラムには、プリプロセッサーの条件付きコンパイル・ディレクティブが含まれています。

/**
 ** This example contains preprocessor
 ** conditional compilation directives.
 **/
 
#include <stdio.h>
 
int main(void)
{
   static int array[ ] = { 1, 2, 3, 4, 5 };
   int i;
 
   for (i = 0; i <= 4; i++)
   {
      array[i] *= 2;
 
#if TEST >= 1
   printf("i = %d¥n", i);
   printf("array[i] = %d¥n",
   array[i]);
#endif
 
   }
   return(0);
}
IBM Copyright 2003