I can't understand why including a text file that contains some C lines in a fortran77 code gives me a warning if I do not use #include. I wrote an example of a code that is supposed to read some text to be added to the main file, test.F:

       program testInclude
       include 'includetest.txt'
       end program

and the includetest.txt file to be included contains the following

#define _TEST_
#ifdef _TEST_
       write(*,*) 'check'

If I compile it with gfortran test.F I get the following warning:


    2 | #define _TEST_
      |  1
Warning: Illegal preprocessor directive

    3 | #ifdef _TEST_
      |  1
Warning: Illegal preprocessor directive

    5 | #endif
      |  1
Warning: Illegal preprocessor directive

while no warnings are given if I use #include instead of include in the 2nd line of test.F. Aren't the fortran include statement and the C #include one supposed to do the same exact thing and add some lines of text to another file? What does the warning mean?

This happens with gcc 12.2.0 on Arch and Mac OS X, and with gcc 4.8.5 on CentOS.

1 Answer 1


Files included by the preprocessor #include directive can contain #defines and the like; files included with the compiler INCLUDE statement must contain only FORTRAN statements.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .