Currently gfortran calls cpp with the option -traditional-cpp. Using this option, newer macros like
#define msg(x) print *, #x
don't work (the #x causes the argument to be quoted). (See url/email for example.)
I couldn't find any standard for fpp. I assume that it is only a Fortran-aware CPP, which is defined in the C99 standard (ISO/IEC 9899:1999, section "22.214.171.124 The # operator").
I would expect that the newer constructs work by default with gfortran, or at least that one can force that mode. The first would simply mean to remove "-traditional-cpp" from the argument list.
Other compilers: Sun Studio f95 and Intel Fortran Compiler both support #x by default.
g95 and NAGware f95 seem to work as gfortran: msg(test) is converted into
One problem without using -tranditional-cpp is that some tokens in C are not tokens in Fortran so you could get the wrong result. This is why -tranditional-cpp is used.
There is no standard for Preprocessed Fortran Source at all.
> One problem without using -tranditional-cpp is that some tokens in C are not
> tokens in Fortran so you could get the wrong result. This is why
> -tranditional-cpp is used.
I though the -lang-fortran, which is passed (according to gfortran -###), takes care of this?
> There is no standard for Preprocessed Fortran Source at all.
Well, that I assumed. But it is still (somehow) based on ISO C's preprocessor.
Confirm my bug. See also 29671 ("#" must be in the first column).
One big problem which prevents omitting the -traditional-cpp is that comments are not ignored. Another example of this is
! .... /*
which is regarded as the beginning of a C/C++ comment. Thus we should add two modes to CPP, one for fixed-form and one for free-form Fortran code.
Additional point, one needs to take care also of continuation lines of the following kind. This should print "Hello Paul" and not "Hello Hans".
#define Paul Hans
! Paul's string
print *,'Hello &
For an initial, incomplete patch see:
> For an initial, incomplete patch see:
Slighly updated version. Set tradtional to 0 in fortran/cpp.c to enable new features, which will fail if the following (work items) are in you Fortran file:
- Spacing needs to be preserved for fixed-form Fortran
(currently fails in the test suite)
- Check that '...''...' work (seems so)
- Problem mentioned in comment 5
* Max linelength option for gfortran and cpp
* Fortran/Fixed-form-source Fortran for cpp
* Should one use c_lang instead of a flag? Advantage for c_lang: Fortran is a language; advantage for flag: the CPP features can be tuned by c_lang.
Created attachment 16029 [details]
libcpp patch (w/o setting traditional = 0 )
Said patch, see comment 7 for TODO items.
*** Bug 29671 has been marked as a duplicate of this bug. ***
Related: All source-file reading should go though libcpp, which requires a better white space handling; cf. https://gcc.gnu.org/ml/fortran/2014-12/msg00003.html
*** Bug 67250 has been marked as a duplicate of this bug. ***
*** Bug 63413 has been marked as a duplicate of this bug. ***