compiler-errors - gfortran在编译文件上不输出ident工具

我使用ident工具从源文件和编译文件中提取RCS关键字字符串。

它当然适用于源代码,也适用于GCC的C编译输出以及G77的fortran编译输出。

$ gcc -o c.out test.c
$ ident test.c c.out 
test.c:
     $Id: 63159761756 $

c.out:
     $Id: 63159761756 $


$ g77 -o g77.out test.f
$ ident test.f g77.out 
test.f:
     $Id: 63159761756 $

g77.out:
     $Id: 63159761756 $

问题是当我使用gfortran编译器来编译fortran代码时。 ident工具无法在编译后的代码中找到RCS关键字,并且什么也不返回!
$ gfortran -o gf.out test.f
$ ident test.f gf.out 
test.f:
     $Id: 63159761756 $

gf.out:

那么,gfortran有什么问题呢?是否有任何优化操作变量,或者ident工具不再能够解析gfortran的编译输出?

请问该如何解决?

编辑:

Fortran源代码:
  PROGRAM HELLO
    CHARACTER*80 ID
    ID =
 *'@(#)$Id: 63159761756 $'
    PRINT '(A)', 'Hello,fortran 77'
    Print *, 'ID is ', ID
    STOP
  END

最佳答案

使用字符串常量,如

  PROGRAM HELLO
  PRINT '(A)', 'Hello,fortran 77'
  Print *, 'ID is ',
 +'@(#)$Id: ident.f,v 1.2 2015/02/24 14:20:49 ig25 Exp ig25 $'
  STOP
  END

您必须确保以某种方式使用它,否则很容易将其删除。

编辑

您必须在某处使用它,以使编译器无法看到它实际上是无用的。目前,我唯一能看到的方法就是骇人听闻的骇客,但无论如何...
  PROGRAM HELLO
  logical, volatile :: print_it = .false.
  PRINT '(A)', 'Hello,fortran 77'
  if (print_it) then
  Print *, 'ID is ',
 +'@(#)$Id: ident.f,v 1.2 2015/02/24 14:20:49 ig25 Exp ig25 $'
  end if
  STOP
  END

在这里,您使用volatile声明告诉编译器不要假设print_it可以为false。可行,但欢迎提出更优雅的建议。

https://stackoverflow.com/questions/28697620/

相关文章:

c# - 根据文本框错误重新定义变量

c# - Unity 在编译有效的 C# 类时遇到问题

compiler-errors - 在Solaris Sparc 11下强制使用Sun Studio

compiler-errors - 由于 glib 错误,无法处理 gobject-introspe

c# - 为什么这种编译方式有所不同?

haskell - 实例化类时发生编译错误

eclipse - 如何修复xtext上的简单错误?

scala - 使用 Deadbolt 2 : overriding method getSubje

asp.net - 错误: SignalRRouteExtension.Mapconnection

c# - MVC3网站编译器错误