-2

Suppose I have a file test.f90 (free-form code) that includes some other file foo.h (fixed code).

The two didn't work well together because they have different comment styles, so I put a preprocessor directive !DIR$ NOFREEFORM at the top of the foo.h source code, which tells Intel's Fortran Compiler ifort to interpret that file as fixed-form source code.

Unfortunately, the rest of my code in test.f90 gets errors that indicate ifort is interpreting it as fixed-form rather than free-form code.

I haven't rigorously checked, but is it possible that the preprocessor directive in foo.h is causing ifort to interpret the code in test.f90 as fixed-form? I didn't think this was possible because ifort treats each included file as a separate compilation, rather than just copy-pasting the code.

Steve Lionel
  • 6,972
  • 18
  • 31
jvriesem
  • 1,859
  • 3
  • 18
  • 40
  • 3
    Possible duplicate of https://stackoverflow.com/questions/22752730/include-both-f-and-f90-file-in-fortran-main-file-header/22753383. I see that this was pointed out to you in a comment to an earlier variant of your question - you indeed *haven't rigorously checked*, you haven't even followed advice already provided. – High Performance Mark Mar 31 '18 at 19:12
  • 1
    !DIR$ NOFREEFORM is not a "preprocessor directive", it is a compiler directive, The documentation says, "When the FREEFORM or NOFREEFORM directives are used, they remain in effect for the remainder of the program unit, or until the opposite directive is used. " So you need the corresponding FREEFORM directive at the end. Or, where you INCLUDE it, bracket the INCLUDE with those directives (the better approach in my view.) – Steve Lionel Mar 31 '18 at 19:51
  • Downvote from me. Please at least *pretend* to put some effort into your question beforehand. – Ross Mar 31 '18 at 22:07

1 Answers1

3

The latest standard states

The effect of the INCLUDE line is as if the referenced source text physically replaced the INCLUDE line prior to program processing.

so it is entirely possible, in fact absolutely inevitable, that the preprocessor directive in the included file causes the compiler to change its interpretation of the code.

include-d files are not separate compilation units.

I guess you should be able to use!DEC$ FREEFORM to switch the compiler's behaviour back again.

High Performance Mark
  • 77,191
  • 7
  • 105
  • 161