带换行符的 Fortran 预处理器宏

Fortran Preprocessor Macro with Newline

我正在尝试将换行符放入预处理器宏中。

我想要这样做的一个原因是取消分配一些变量,但首先要检查以确保它们已分配。如果它们没有被分配,那么应该有一个有用的错误。在这个例子中:

$ cat main.F90 
program main
   implicit none
   integer :: n = 10
   integer, allocatable, dimension(:) :: x, y

   allocate(x(n))

#define check_deallocate(QQQ) \
   if (.not. allocated(QQQ)) then \
      write(*,*) '** Error, QQQ is not allocated' \
      error stop \
   else \
      deallocate(QQQ) \
   endif

   check_deallocate(x)
   check_deallocate(y)

end program

对于这段代码,我得到以下信息:

$ gfortran -E main.F90   #-E outputs the preprocessed source
...
   if (.not. allocated(x)) then       write(*,*) '** Error, x is not allocated'       error stop    else       deallocate(x)    endif
   if (.not. allocated(y)) then       write(*,*) '** Error, y is not allocated'       error stop    else       deallocate(y)    endif
...

显然,这是不可取的,因为不遵守 132 个字符的限制。因此我的问题是:在预处理源代码中包含换行符的语法是什么?

这里有一些我发现的东西并不能完全回答我的问题

如果我所要求的是不可能的,这也是我的问题的答案。另外,我有点意识到 fortran 预处理器缺乏标准化,但我仍然要求一个相对通用的解决方案。

它本身是不可能的,但如果允许您使用单独的预处理步骤,您可以使用以下方法来完成:

SUFFIXES:
.SUFFIXES: .f90 .o

.f90.o:
    fpp -P $/n/g' > $*.ftn
    ifort -free -c $*.ftn

(未经测试。我在 this link 找到了这个建议)