What should COMPILER_OPTIONS() return in Fortran?

痴心易碎 提交于 2019-12-10 20:26:21

问题


Fortran 2008 added a new procedure called COMPILER_OPTIONS() which according to GNU documentation should return a string with the options used for compiling the file. According to Fortran 2003 status wiki, almost all compilers including GNU and PGI seem to support this feature.

I created a simple program COMPILER_OPTIONS.f08 shown below

use iso_fortran_env
   print '(4a)', 'This file was compiled by using the options ', compiler_options()
end

Here are my results from gfortran and pgfortran

Gfortran 5.4 with no compile time options

$ gfortran COMPILER_OPTIONS.f08 && ./a.out 
This file was compiled by using the options -mtune=generic -march=x86-64

Gfortran 5.4 with -O3 passed at compile time

$ gfortran -O3 COMPILER_OPTIONS.f08 && ./a.out 
This file was compiled by using the options -mtune=generic -march=x86-64 -O3

PGI 17.4 with no option passed at compile time

$ pgfortran COMPILER_OPTIONS.f08 && ./a.out 
This file was compiled by using the options COMPILER_OPTIONS.f08 

PGI 17.4 with -O3 passed at compile time

$ pgfortran -O3 COMPILER_OPTIONS.f08 && ./a.out 
This file was compiled by using the options COMPILER_OPTIONS.f08 -O3 -Mvect=sse -Mcache_align -Mpre 

Given the above output, I have following questions

  1. What is COMPILER_OPTIONS() procedure expected to return as per Fortran 2008?
  2. What is the status of support across different compilers?

EDIT : Changed flag to -O3 (Optimization Level 3) from -o3 (Output file 3). Thanks to the feedback from Pierre and francescalus.


回答1:


Fortran 2008 describes the function as (13.8.2.6):

Processor-dependent string describing the options that controlled the program translation phase.

This function returns a "default character scalar with processor-dependent length."

That's an awful lot of freedom for a compiler. There's no indication from the results presented here to suggest any non-compliance.



来源:https://stackoverflow.com/questions/46464763/what-should-compiler-options-return-in-fortran

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!