12.1. Conditional Compilation#

The following example illustrates the use of conditional compilation using the OpenMP macro _OPENMP. With OpenMP compilation, the _OPENMP macro becomes defined.

//%compiler: clang
//%cflags: -fopenmp

/*
* name: cond_comp.1
* type: C
*/
#include <stdio.h>

int main()
{

# ifdef _OPENMP
    printf("Compiled by an OpenMP-compliant implementation.\n");
# endif

    return 0;
}

The following example illustrates the use of the conditional compilation sentinel. With OpenMP compilation, the conditional compilation sentinel !$ is recognized and treated as two spaces. In fixed form source, statements guarded by the sentinel must start after column 6.

!!%compiler: gfortran
!!%cflags: -fopenmp

! name: cond_comp.1
! type: F-fixed
      PROGRAM EXAMPLE

C234567890
!$    PRINT *, "Compiled by an OpenMP-compliant implementation."

      END PROGRAM EXAMPLE