简体   繁体   English

nagfor预处理器的用户定义错误

[英]User-defined errors with nagfor preprocessor

I'm trying to abort compilation if an unsupported fortran compiler is used. 如果使用不受支持的fortran编译器,我正试图中止编译。 The nagfor preprocessor defines the macro NAGFOR , so I wrote the following test program: nagfor预处理器定义宏NAGFOR ,所以我编写了以下测试程序:

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或ifort编译时,我收到了预期的错误消息

$ 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给出了不同的错误

$ 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. 我找不到如何在nagfor fpp文档中创建错误,所以也许#error不存在。 In which case, is there an alternative approach to get the same effect? 在哪种情况下,是否有另一种方法可以获得相同的效果?

I work on the NAG Compiler. 我在NAG编译器上工作。 fpp is intended to be pretty lightweight in terms of operation (and functionality). fpp在操作(和功能)方面非常轻量级。 It originates from Sun; 它起源于太阳; we are using a version based on the netlib one from http://netlib.org/fortran/fdfpp.tgz . 我们正在使用http://netlib.org/fortran/fdfpp.tgz中基于netlib的版本。

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. fpp手册( http://www.nag.co.uk/nagware/np/r60_doc/fpp.html )没有将#error为您所发现的支持。

As francescalus suggests, the best way to acheive what you want would be with something along the lines of 正如francescalus所说,实现你想要的东西的最好方法就是用一些东西

program foo

  implicit none

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

end program foo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 gfortran:非法的预处理程序指令和无效的字符/非数字字符编译错误 - gfortran: Illegal preprocessor directive & Invalid character/non-numeric character compile errors 在解决方案中编译一个CS项目两次,一次定义一个预处理程序常量,一次不使用它 - Compile a single CS project in a solution twice, one with a preprocessor constant defined and one without it 是否可以强制可执行文件使用用户定义的“ malloc”? - It is possible to force an executable to use an user defined 'malloc'? Git以用户身份在主目录中安装:错误? - Git Install in Home Directory as User: Errors? 由于缺少变量导致的编译器错误(变量在不同的类中定义) - Compiler errors due to missing variables (the variable is defined in a different class) 用户定义的编译时间格式化消息 - User defined compile time formatted message Maven编译时如何包含用户定义的包 - how to include user defined package when do maven compile Java是否也在用户定义的通用类中实现类型擦除? - Does java implement type erasure in user defined generic classes too? 预处理程序指令如何在C中工作? - How preprocessor directives works in C? 预处理器宏字符串化 - preprocessor macro stringify
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM