zhu_youren 发表于 2015-3-16 11:05:22

IVF如何编译通过预处理宏

编译Fortran程序,其中的一段
#ifdef COUPLING            
            if (modele2d==1) then
#endif
                call is_in_cell(x,y,kvol,in_cell)
#ifdef COUPLING
            else
                call is_in_cell_1d(x,y,kvol,in_cell)
            endif
#endif
编译不通过:1>src\prepare_obs.f90(131): warning #5117: Bad # preprocessor line
1>src\prepare_obs.f90(133): warning #5117: Bad # preprocessor line
1>src\prepare_obs.f90(135): warning #5117: Bad # preprocessor line
1>src\prepare_obs.f90(139): warning #5117: Bad # preprocessor line
所选平台是VS2012+IVF2013,请问有什么办法可以解决?

vvt 发表于 2015-3-16 11:29:02

Fortran 语法里没有关于预处理宏的指令,所以都是各家编译器扩展的。

ivf 这样用:

!DEC$ IF DEFINED ( COUPLING )
             if (modele2d==1) then
!DEC$ endif
               call is_in_cell(x,y,kvol,in_cell)
!DEC$ IF DEFINED ( COUPLING )
             else
               call is_in_cell_1d(x,y,kvol,in_cell)
             endif
!DEC$ endif

zhu_youren 发表于 2015-3-16 14:09:09

vvt 发表于 2015-3-16 11:29
Fortran 语法里没有关于预处理宏的指令,所以都是各家编译器扩展的。

ivf 这样用:


灰常感谢vvt!!!

fcode 发表于 2015-3-16 14:17:37

define 和 undefine 也不一样,分别是
!DEC$ DEFINE COUPLING
!DEC$ UNDEFINE COUPLING

zhu_youren 发表于 2015-3-17 09:05:56

fcode 发表于 2015-3-16 14:17
define 和 undefine 也不一样,分别是
!DEC$ DEFINE COUPLING
!DEC$ UNDEFINE...

受教了,灰常感谢fcode君!!!

zhu_youren 发表于 2015-3-17 09:43:24

zhu_youren 发表于 2015-3-17 09:05
受教了,灰常感谢fcode君!!!

那简单的总结一下IVF中预处理宏的用法(与C对应)就是
#ifdef COUPLING → !DEC$ IF DEFINED ( COUPLING ) ,
#endif → !DEC$ endif,
#else → !DEC$ else ,
#define COUPLING →!DEC$ DEFINE COUPLING   
#undefCOUPLING →!DEC$ UNDEFINE COUPLING

pasuka 发表于 2015-3-18 14:02:28

编译的时候加fpp或cpp选项呢?
ivf和gcc照理都是支持的

phcs 发表于 2015-8-3 09:20:31

#ifndef对应的是什么呢?

vvt 发表于 2015-8-3 13:08:58

phcs 发表于 2015-8-3 09:20
#ifndef对应的是什么呢?

!DEC$ IF .NOT. DEFINED ( COUPLING )

phcs 发表于 2015-8-3 19:30:36

vvt 发表于 2015-8-3 13:08
!DEC$ IF .NOT. DEFINED ( COUPLING )

这个在哪儿可以查到呢?您那有什么书上有吗?
页: [1] 2
查看完整版本: IVF如何编译通过预处理宏