Bug 37032 - including "file.F90" - no CPP processing
Summary: including "file.F90" - no CPP processing
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.1
: P3 normal
Target Milestone: 4.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-08-05 18:51 UTC by Greg Odom
Modified: 2008-08-18 20:51 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Greg Odom 2008-08-05 18:51:16 UTC
Multi-line comments in an included file trigger "invalid character in name" compiler error.

!file1.F95
program file1
  include 'file2.F95'
  stop
end program

!file2.F95
/* blah */
Comment 1 Tobias Burnus 2008-08-05 19:22:14 UTC
Cf. multiple topic PR 35707.

The problem is that
  include 'file2.F95'
is not processed through CPP. I'm not sure whether it should and when it should (file extension .F/F90/F95/F03/F08/FPP/FOR/fpp, always, or never).

One possibility is to use:
#include "file2.F95"
in this case CPP includes the file before it hands it to the Fortran part of the compiler.
Comment 2 Greg Odom 2008-08-05 21:07:41 UTC
I guess that would only work with GCC but if we can get OpenMP working, that might be good enough.  Thank you ^_^.
Comment 3 kargls 2008-08-05 21:17:49 UTC
(In reply to comment #1)
> Cf. multiple topic PR 35707.
> 
> The problem is that
>   include 'file2.F95'
> is not processed through CPP. I'm not sure whether it should and when it should
> (file extension .F/F90/F95/F03/F08/FPP/FOR/fpp, always, or never).
> 

The standard simply says the text in file2.F95 is included
at the location of the include line.  It does not and suppose
the standard will never discuss whether file2.F95 should be
pre-processed before inclusion.

This looks like pilot error in that Fortran's INCLUDE does not
mean the same thing as C's #include.
Comment 4 Greg Odom 2008-08-05 21:30:34 UTC
(In reply to comment #3)
> (In reply to comment #1)
> > Cf. multiple topic PR 35707.
> > 
> > The problem is that
> >   include 'file2.F95'
> > is not processed through CPP. I'm not sure whether it should and when it should
> > (file extension .F/F90/F95/F03/F08/FPP/FOR/fpp, always, or never).
> > 
> 
> The standard simply says the text in file2.F95 is included
> at the location of the include line.  It does not and suppose
> the standard will never discuss whether file2.F95 should be
> pre-processed before inclusion.
> 
> This looks like pilot error in that Fortran's INCLUDE does not
> mean the same thing as C's #include.
> 

Does the Fortran standard mention preprocessing at all?  That works in g95, but  we are beginning to move away from that.  Is a copy of the standard freely available?  I would like for this to work with as many different compilers and systems as possible.
Comment 5 kargls 2008-08-05 21:44:24 UTC
(In reply to comment #4
> Does the Fortran standard mention preprocessing at all?

No.  Section 1.1 (the very 1st section) states


1.1      Scope
ISO/IEC 1539 is a multipart International Standard; the parts are published
separately. This publication, ISO/IEC 1539-1, which is the first part,
specifies the form and establishes the interpretation of programs expressed in
the base Fortran language. The purpose of this part of ISO/IEC 1539 is to
promote portability, reliability, maintainability, and efficient execution of
....
The third part, ISO/IEC 1539-3, defines a standard conditional compilation facility for Fortran.  A processor conforming to part 1 need not conform to
ISO/IEC 1539-2 or ISO/IEC 1539-3; however, conformance to either assumes conformance to this part.

> Is a copy of the standard freely available?

The Standard is not free.  You, however, can find drafts of the
various standards that are provided so people can provide feedback
to J3.  See the gfortran wiki for pointers to drafts.
Comment 6 Greg Odom 2008-08-05 22:04:40 UTC
(In reply to comment #5)
ok.  Thank you very much for your help ^_^.
Comment 7 Tobias Burnus 2008-08-06 06:12:42 UTC
> Does the Fortran standard mention preprocessing at all?

Yes, part 3 of the Fortran standard is about preprocessing ("Conditional Compilation", "CoCo"), however, to my knowledge hardly anyone uses it and no compiler implements it. (There exists a Fortran program which can be used as coco preprocessor, see link below.)

The de-facto standard for preprocessing is CPP (C Pre Processor) sometimes also called FPP. However, this is only standardized for C and not for Fortran, which causes issues as not every compiler acts the same. Issues:

1. Are newer CPP features supported?
2. Are Fortran "INCLUDE"d files also preprocessed?

gfortran/netlib's fpp/NAG f95/openf95/sunf95: (1) no,(2) no
g95:   no/yes
ifort: yes/no, 

(There are plans to support (1) in gfortran, see PR 28662.)


> Is a copy of the standard freely available?

Yes and no. The latest drafts before the standard went to ISO are available for free, which are said to be the same except for layout. See links at
http://gcc.gnu.org/wiki/GFortranStandards

> I would like for this to work with as many different compilers and
> systems as possible.

Then I really suggest to use  #include "...", which should work with any compiler which does CPP preprocessing.
Comment 8 Daniel Franke 2008-08-14 21:17:11 UTC
IMO, not pre-processing INCLUDEd files (as opposed to #include'd ones) is a feature, not a bug. 

Maybe we should make a final decision on this, i.e. if bug or feature, and state/document it, once and for all?
Comment 9 Daniel Franke 2008-08-18 20:47:31 UTC
Subject: Bug 37032

Author: dfranke
Date: Mon Aug 18 20:46:08 2008
New Revision: 139215

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=139215
Log:
2008-08-18  Daniel Franke  <franke.daniel@gmail.com>

        PR fortran/37032
        * gfortran.texi: Document decision on include file handling in
        preprocessed files.


Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/gfortran.texi

Comment 10 Daniel Franke 2008-08-18 20:51:02 UTC
Closing as WONTFIX.

Reference:
    http://gcc.gnu.org/ml/fortran/2008-08/msg00071.html
(and following).

(Updated) Documentation about gfortran's behaviour with preprocessing can be found in sections 1.3 and 2.3 of the manual (http://gcc.gnu.org/onlinedocs/gfortran/).