3

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?

francescalus
  • 30,576
  • 16
  • 61
  • 96
John
  • 207
  • 1
  • 7
  • `fpp` seems to not know the `#error` directive. Look in the manual what are your other possibilities. – Vladimir F Героям слава Apr 13 '15 at 16:39
  • One possible approach could be to put some obvious junk that the compiler itself would reject fatally. Not ideal (so not answer quality), but unless you've masses to pre-processes (and so want to abort that early) it could have the same end result. [But also, fatal aborting is not portable.] – francescalus Apr 13 '15 at 16:55

1 Answers1

1

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
MatCross
  • 389
  • 1
  • 5