Why compiling Fortran code with include is different from #include?
0
votes
1
answer
591
views
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'
#endif
If I compile it with gfortran test.F
I get the following warning:
includetest.txt:2:2:
2 | #define _TEST_
| 1
Warning: Illegal preprocessor directive
includetest.txt:3:2:
3 | #ifdef _TEST_
| 1
Warning: Illegal preprocessor directive
includetest.txt:5:2:
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.
Asked by Giorgio Maria Cavallazzi
(3 rep)
Nov 21, 2022, 09:50 PM
Last activity: Nov 21, 2022, 11:18 PM
Last activity: Nov 21, 2022, 11:18 PM