You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running gfortran one actually does not run the compiler, but the compiler driver. This driver interprets the command line options given, and hands the work off to the actual compiler, the assembler, and the linker. By default, this compiler driver decides by the extensions of the given file names what to do. A file named foo.c is handed to the C compiler and a file named foo.f90 is handed to the Fortran 95 compiler, etc. To overrule this behavior, one has to precede the filename by the argument -x lang where lang is a string identifying the requested language. For Fortran 95 this is f95
I was just wondering if there might by any reason to cut the gfortran compiler driver out of the picture, and use the "low-level" gcc compiler commands directly. I'm not sure how this affects Fortran-specific flags.
So far I only have one (nasty) reason, why you would want to do this - to force using the C preprocessor (in general this is a bad idea). Say I want to gain access to some macros defined in a C header:
! main.F90
#include <limits.h>
program main
implicit none
print *, "size of C CHAR_BIT = ", CHAR_BIT
end program
I can then run only the C preprocessor with the command
$ gcc -x c -E -P main.F90
program main
implicit none
print *, "size of C CHAR_BIT = ", 8
end program
where the -P flags instructs the preprocessor to omit generation of linemarkes.
Something similar can be done with Intel compilers:
$ icc -EP main.F90 | grep "\S"
program main
implicit none
print *, "size of C CHAR_BIT = ", 8
end program
The -EP flag causes the preprocessor to output to stdout omitting the line directives. The additional grep command is to remove the empty lines, which were left by header expansion and omitting linemarkers (annoyingly, the behavior of gcc and icc differs).
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
From the gfortran pages:
I was just wondering if there might by any reason to cut the
gfortran
compiler driver out of the picture, and use the "low-level"gcc
compiler commands directly. I'm not sure how this affects Fortran-specific flags.So far I only have one (nasty) reason, why you would want to do this - to force using the C preprocessor (in general this is a bad idea). Say I want to gain access to some macros defined in a C header:
I can then run only the C preprocessor with the command
where the
-P
flags instructs the preprocessor to omit generation of linemarkes.Something similar can be done with Intel compilers:
The
-EP
flag causes the preprocessor to output to stdout omitting the line directives. The additional grep command is to remove the empty lines, which were left by header expansion and omitting linemarkers (annoyingly, the behavior ofgcc
andicc
differs).Beta Was this translation helpful? Give feedback.
All reactions