Silverfrost Logo About Us | Contact Us

Conditonal compilation and detecting .NET at runtime

For an introduction to conditional compilation see Conditional compilation.

FTN95 uses IS_CLR@ in two different contexts.

1) As a macro in conditional compilation, and

2) as the name of an intrinsic function.

In both cases IS_CLR@ returns TRUE only if it is a .NET program (i.e. /CLR is on the command line).

Here is an example of its use in conditional compilation:

  OBJECT('System.Int32') :: j
  INTEGER :: j

Note that the FTN95 option /FPP is only required for a Win32 platform (when /CLR is not present, because it is implied by /CLR). /SPARAM and /VPARAM can be used for .NET but /SPARAM cannot be used to set the value of IS_CLR@.

Here is an example of the use of IS_CLR@ at runtime:

IF (IS_CLR@()) PRINT *, 'Running under .NET'

The compiler will issue a warning that the test will always or never succeed. This can be ignored.

The pre-processor can use .AND. and .OR. in very simple expressions. Note that .AND. and .OR. have equal precedence and that brackets cannot be used to group expressions. You must use a comparison if .AND. or .OR. are used. Thus the directive:


will produce an error and must be written:

CIF (IS_CLR@ == 1 .AND. KIND == 3)

Note also that continuations are ignored by the pre-processor. However, it does not truncate lines.

The pre-processor also supports CELSEIF and CERROR. The CERROR directive simply prints the given string as a compilation error and halts compilation. This can be used to trap invalid VPARAM combinations. For example:

CIF (IS_CLR@ == 1 .AND. KIND == 3)
  CERROR '"/VPARAM KIND 3" is not supported under .NET'
  INTEGER, PARAMETER :: kind = 3



Copyright © 1999-2017 Silverfrost Limited