Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Fortran中的CPP预处理语句可以缩进吗?_Fortran_C Preprocessor_Indentation_Gfortran_Preprocessor - Fatal编程技术网

Fortran中的CPP预处理语句可以缩进吗?

Fortran中的CPP预处理语句可以缩进吗?,fortran,c-preprocessor,indentation,gfortran,preprocessor,Fortran,C Preprocessor,Indentation,Gfortran,Preprocessor,我对使用Fortran预处理语句相当陌生,有一个问题可能是我自己的问题。Fortran预处理语句可以缩进吗?我在Linux(openSUSE Leap)上使用Gfortran 4.8.1进行了测试,结果证明它根本不能缩进 以下代码main.f90适用于gfortran-cpp main.f90-o main: program main implicit none #ifdef DEBUG print *, "I am in debug mode" #endif prin

我对使用Fortran预处理语句相当陌生,有一个问题可能是我自己的问题。Fortran预处理语句可以缩进吗?我在Linux(openSUSE Leap)上使用Gfortran 4.8.1进行了测试,结果证明它根本不能缩进

以下代码main.f90适用于
gfortran-cpp main.f90-o main

program main
    implicit none
#ifdef DEBUG
    print *, "I am in debug mode"
#endif 
    print *, "hello world!"
end program main
但是下面抛出了一个错误:

program main
    implicit none
    #ifdef DEBUG
    print *, "I am in debug mode"
    #endif 
    print *, "hello world!"
end program main
错误消息是
错误:在(1)
处名称中的字符无效。
这是否意味着我们应该始终从行的第一个开头开始编写预处理语句,或者它只是编译器特定的规则?任何帮助都将不胜感激,并提前表示感谢

您可以使用
C
预处理器进行处理,然后编译处理后的文件,也就是说,假设您的程序位于
main.f90
,然后类似于:

cpp -nostdinc -C -P -w main.f90 > _main.f90
gfortran -o main _main.f90

在这方面,这个问题非常有用:

不,它们不能缩进,因为gfortran运行的CPP不允许缩进。它们必须始终从第一列开始

您可以手动运行CPP,但要非常小心。 如果在某个地方使用
/
字符串连接运算符,预处理器会将其视为注释。您必须使用@ewcz在其答案中显示的
-C
标志,该标志禁止丢弃注释


有些编译器提供了自己的FPP预处理器,其性能有所不同。

谢谢您的评论。gfortran是否支持任何其他预处理器,或者cpp只是唯一可用的预处理器?感谢您的回答,链接非常相关和有用。