compilationfortranpreprocessornag-fortran

User-defined errors with nagfor preprocessor


I'm trying to abort compilation if an unsupported fortran compiler is used. The nagfor preprocessor defines the macro NAGFOR, so I wrote the following test program:

program foo

  implicit none

#ifdef NAGFOR
  PRINT *, "Hello from nagfor"
#else
#error "Compiler not supported"
#endif

end program foo

When I compile with gfortran or ifort, I get the expected error message

$ gfortran foo.F90
foo.F90:8:2: error: #error "Compiler not supported"

$ ifort foo.F90
foo.F90(8): #error:  "Compiler not supported"

but nagfor gives a different error

$ nagfor foo.F90
NAG Fortran Compiler Release 5.3.1(907)
"foo.F90", line 8: error: unknown fpp directive.

I can't find any mention of how to create an error in the nagfor fpp documentation so maybe #error doesn't exist. In which case, is there an alternative approach to get the same effect?


Solution

  • I work on the NAG Compiler. fpp is intended to be pretty lightweight in terms of operation (and functionality). It originates from Sun; we are using a version based on the netlib one from http://netlib.org/fortran/fdfpp.tgz.

    The fpp manual (http://www.nag.co.uk/nagware/np/r60_doc/fpp.html) does not document #error as being supported, which you have discovered.

    As francescalus suggests, the best way to acheive what you want would be with something along the lines of

    program foo
    
      implicit none
    
    #ifdef NAGFOR
      PRINT *, "Hello from nagfor"
    #else
      error "Compiler not supported"
    #endif
    
    end program foo