gfortran -cpp sometimes confused by '/*'
Steve Kargl
sgk@troutmask.apl.washington.edu
Fri Jun 26 15:42:00 GMT 2015
On Fri, Jun 26, 2015 at 12:47:21PM +0100, sam tygier wrote:
> On 25/06/15 17:23, Steve Kargl wrote:
> > On Thu, Jun 25, 2015 at 04:34:31PM +0100, sam tygier wrote:
> >> I am trying to use some #ifdef in some fortran code in order to smooth
> >> over a gfortran/ifort difference. This requires using the flag -cpp.
> >> However this causes a line containing '\*' to be misinterpreted giving
> >> the error:
> >> Error: unterminated comment
> >> I have tried with 5.1.1 and 4.7.2.
> >>
> >> I can reduce the issue down to the program:
> >> PROGRAM a
> >> WRITE(*,FMT='( '' /* '' )')
> >> WRITE(*,FMT='(
> >> > '' /* '' )')
> >> ENDPROGRAM
> >> This compile and runs fine with out -cpp, but the second write statement
> >> fails with -cpp. Maybe because the parser in cpp detects the first
> >> instance as being within a string. In ifort it does not cause a problem.
> >>
> >> While I can work around this, it seems like the wrong behaviour. Is this
> >> a bug, or just an inherent limitation.
> >>
> > Yes, no, maybe.
> >
> > The -cpp is instructing gfortran to pass your code through
> > the C pre-processor before it actually passes the code
> > through the Fortran compiler. What a C preprocessor does
> > to the code is outside of the scope of the Fortran standard.
> > A programmer that wishes to use a C preprocessor needs
> > to ensure the output of that preprocessing is actual Fortran.
> > In your case, the pre-processing output is obviously 'not Fortran'.
> >
> > So, the C pre-processor appears to not understand splitting
> > a string across lines via Fortran's continuation mechanism.
> >
> So is there a need for a fortran preprocessor, or a fortran mode in cpp?
> I.e. one that either understood fortran's syntax enough to decide
> whether something is inside a string literal or not, or one that does
> not remove c/c++ style comments.
>
This is only my opinion. Others that actively contribute to
gfortran development may have opinions that do not align with
mine.
The simply answer is 'no'. With very little manpower to address
real issues/bugs in gfortran, it would be a waste of valuable
developer resources to 'fix' cpp to handle your needs. The
format string that you want to split across a line with Fortran
continuation can be constructed by string concatenation and
internal write. The 'fix' to your code would seem to be trivial.
Now, if your set on your code is sacred, then you might consider
using fpp instead of cpp. See http://www.netlib.org/fortran/index.html
I haven't used fpp in years, so I can say if it will work for you.
There is also the option that you fix cpp to meet your needs.
No one would stop you, and if you are successful you could
contribute the patch back to the community.
--
Steve
More information about the Fortran
mailing list