本文介绍了在 Fortran 文件中包含语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Fortran 模块文件(filename.F),其中包含一行语句:

I had a Fortran module file (filename.F), which contains a line of statement:

#include "module_io_domain_defs.inc"

我不太明白.为什么是#"符号.不应该只是

which I don't quite understand. Why is a "#" symbol. Should not be just

include "module_io_domain_defs.inc"

我知道在编译过程中,*.F 文件变成了*.f90 文件.如何理解上面的语句以及编译过程是如何工作的?

I know during the compilation process, the *.F file becomes *.f90 file. How to understand the above statement and how dose the compilation process work?

推荐答案

# 指定一个 C 预处理器指令.因此,#include 不是由 Fortran 编译器处理,而是由 C 预处理器(cppc-preprocessor).大写的 .F 而不是 f 通常告诉编译器在编译之前运行 cpp.

The # designates a C preprocessor directive. Therefore the #include is not processed by the Fortran compiler but by a C preprocessr (cpp, c-preprocessor). The capital .F instead of f typically tells the compiler to run cpp before compiling.

主要区别在于 #include 包含的文件将再次由 cpp 处理,而仅由 include 包含的文件将在编译之前不被任何东西处理.

The main difference is that the file included by #include will again be processed by cpp, whereas a file included just by include will not be processed by anything before compiling.

如果编译器无法识别大写F,也可以通过传递-cpp-fpp等标志来请求预处理器在后缀中.

The preprocessor can also be requested by passing a flag such as -cpp or -fpp if the compiler does not recognize the capital F in the suffix.

这篇关于在 Fortran 文件中包含语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 01:49