可以缩进Fortran中的CPP预处理语句吗? [英] Can CPP preprocessing statement in Fortran be indented?

查看:256
本文介绍了可以缩进Fortran中的CPP预处理语句吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Fortran预处理语句相当新,并且有一个可能非常原生的问题。可以缩进Fortran预处理语句吗?我在Linux上使用Gfortran 4.8.1进行了测试(openSUSE Leap),结果证明它不能缩进。

I am fairly new to use Fortran preprocessing statement and have a question which is probably pretty native. Can Fortran preprocessing statement be indented? I tested using Gfortran 4.8.1 on Linux (openSUSE Leap) and it turned out I it can not be indented at all.

以下代码main.f90与 gfortran -cpp main.f90 -o main

The following code main.f90 works with 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

但是下面会报错:

But the following throws an error:

program main
    implicit none
    #ifdef DEBUG
    print *, "I am in debug mode"
    #endif 
    print *, "hello world!"
end program main

错误信息是错误:无效字符(1)的名字。
这是否意味着我们应该始终从该行的第一行开始写预处理语句,或者它只是一个编译器特定的规则?任何帮助将不胜感激,并提前致谢!

The error message is Error: Invalid character in name at (1). Does this mean that we should always write the preprocessing statement from the first beginning of the line or it is just a compiler specific rule? Any help would be greatly appreciated and thanks in advance!

推荐答案

不,它们不能缩进,因为gfortran在传统模式,不允许缩进。他们必须始终从第一列开始。

No, they cannot be indented because gfortran runs CPP in traditional mode which does not allow indentation. They must always start in the first column.

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

You could run CPP manually, but be very very careful about that. If you use the // string concatenation operator somewhere the preprocessor would treat it as a comment. You must use the -C flag as shown by @ewcz in his/her answer which disables discarding of comments.

一些编译器提供自己的FPP预处理器,其行为不同。

Some compilers supply their own FPP preprocessor which behaves differently.

这篇关于可以缩进Fortran中的CPP预处理语句吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆