No output of ident tool on compiled file by gfortran

115 views Asked by At

I use ident tool to extract RCS keyword strings from both source file and compiled file.

It certainly works for source codes, and also works for C compiled output by GCC as well as fortran compiled output by G77.

$ 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 $

The problem is when I use gfortran compiler to compile the fortran code. The ident tool CANNOT find the RCS keyword in the compiled code, and returns nothing!

$ gfortran -o gf.out test.f
$ ident test.f gf.out 
test.f:
     $Id: 63159761756 $

gf.out:

So, what is wrong with gfortran? Is there any optimization which manipulates the variables, or ident tool is not able to parse the complied output of gfortran anymore?

How can I solve this issue please?

Edit:

Fortran Source Code:

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

There are 1 answers

1
AudioBubble On

Use a string constant, as in

  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

You will have to make sure to use it somehow, or it is liable to be removed.

Edit

You have to use it somewhere, in such a way that the compiler cannot see that it is actually useless. The only way that I can see at the moment is a bit of a horrible hack, but anyway...

  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

Here, you tell the compiler with the volatile declaration never to assume that print_it could be false. Works, but more elegant suggestions are welcome.