Bug 28662 - fpp call of gfortran: -traditional-cpp versus newer macros like #x
Summary: fpp call of gfortran: -traditional-cpp versus newer macros like #x
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.2.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 29671 63413 67250 118161 (view as bug list)
Depends on: 58334 67623
Blocks: 45179 64273
  Show dependency treegraph
 
Reported: 2006-08-09 14:04 UTC by tobias.burnus
Modified: 2024-12-21 06:39 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-10-31 13:03:00


Attachments
libcpp patch (w/o setting traditional = 0 ) (1.94 KB, patch)
2008-08-06 06:25 UTC, Tobias Burnus
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description tobias.burnus 2006-08-09 14:04:08 UTC
See http://gcc.gnu.org/ml/fortran/2006-08/msg00145.html

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 "6.10.3.2 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
  print *,#hello
Comment 1 Andrew Pinski 2006-08-09 18:03:07 UTC
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.
Comment 2 tobias.burnus 2006-08-09 18:10:05 UTC
> 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.
Comment 3 Tobias Burnus 2006-10-31 13:03:00 UTC
Confirm my bug. See also 29671 ("#" must be in the first column).
Comment 4 Tobias Burnus 2008-02-08 17:54:51 UTC
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.
Comment 5 Tobias Burnus 2008-04-23 19:29:32 UTC
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 &
  &Paul'
end
Comment 6 Tobias Burnus 2008-07-30 18:06:16 UTC
For an initial, incomplete patch see:
http://gcc.gnu.org/ml/fortran/2008-07/msg00248.html
Comment 7 Tobias Burnus 2008-08-06 06:24:15 UTC
> For an initial, incomplete patch see:
> http://gcc.gnu.org/ml/fortran/2008-07/msg00248.html

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.
Comment 8 Tobias Burnus 2008-08-06 06:25:44 UTC
Created attachment 16029 [details]
libcpp patch (w/o setting   traditional = 0 )

Said patch, see comment 7 for TODO items.
Comment 9 Francois-Xavier Coudert 2012-03-03 14:36:27 UTC
*** Bug 29671 has been marked as a duplicate of this bug. ***
Comment 10 Tobias Burnus 2014-12-11 16:21:20 UTC
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
Comment 11 Manuel López-Ibáñez 2015-08-18 10:21:17 UTC
*** Bug 67250 has been marked as a duplicate of this bug. ***
Comment 12 Dominique d'Humieres 2015-08-30 14:37:17 UTC
*** Bug 63413 has been marked as a duplicate of this bug. ***
Comment 13 Andrew Pinski 2024-12-21 06:39:14 UTC
*** Bug 118161 has been marked as a duplicate of this bug. ***