Re: Preprocess files with gcc/gfortran vs. cpp

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Oh, sorry, I haven't made it clear. I do not want to mix C and fortran.
I simply want the preprocessor capabilities in fortran as they work in C.
I want to dynamically create a large range of modules/variable-types etc.
This is much easier using preprocessors.
I know one could do bash/sed/functions/awk/etc combinations to arrive
at the same... but... :)

2016-02-19 22:27 GMT+01:00 LMH <lmh_users-groups@xxxxxxxxxxx>:
>
>
> Nick Papior wrote:
>> Damnit, I was kind-of hoping this would not break compatibility. :(
>>
>> Then I guess I am forced to use cpp to create my actual sources.
>>
>> Thanks for the prompt answer!
>>
>> PS. Are there options to use the C-processor with gfortran?
>> I tried:
>> $> gfortran -Xpreprocessor "-x c11-cpp-input" <source>
>> f951: Error: command line option ‘-x c11-cpp-input’ is valid for the
>> driver but not for Fortran
>>
>> hrmph...
>>
>> 2016-02-19 20:30 GMT+01:00 Jonathan Wakely <jwakely.gcc@xxxxxxxxx>:
>>> On 19 February 2016 at 19:01, Nick Papior wrote:
>>>> Am I missing some point here?
>>>> I would have expected gcc/gfortran to use the _same_ preprocessing
>>>> utility as that provided in cpp?
>>>
>>> By default cpp works in C mode, but when invoked by the Fortran
>>> front-end it runs in a different mode. If you use cpp -x f97-cpp-input
>>> then it works in F95 mode, and you get results consistent with
>>> invoking gcc on a .f file, or invoking gfortran.
>>>
>>> I don't know why cpp treats C and Fortran input differently, but
>>> that's why you don't see what you expect.
>>
>>
>>
>
>> PS. Are there options to use the C-processor with gfortran?
>
> With g77, if you named your src file with the .FPP extension, the
> compiler would run the code through the c pre-processor and then compile
> as fortran. This would let you use c style includes and compiler
> directives for code compiled as fortran. You cannot use fortran style
> includes in the same file (like a common statement), you have to choose
> one or the other.
>
> This is the make rule I used,
>
> INCLUDES = -I ${SOURCELOC}/src_common_depend
> OPTIMIZE = -O2
> FCOMP = g77-3
> FCFLAGS = $(INCLUDES) $(OPTIMIZE) -mno-cygwin
>
> $(BDIR)/%.o: $(SOURCELOC)/%.FPP
>         $(FCOMP) $(FCFLAGS) -c -o $@ $<
>
> the no-cygwin flag is depreciated and as I said, this example was for
> gcc3/g77. I have done some of this with gfortran, but only for linux.
>
> In some ways, it can be easier to separate your cpp and fortran code and
> just have your fortran be a function called from cpp. Let the fortran
> have it's own variable namespace and use the fortran pre-processor. As
> long as you can send and return what you need to and from the fotrran
> function, everything should work fine. It's not supper efficient since
> the fortran and c code often have their own copies of each variable, but
> that is often not a major issue anymore.
>
> LMH
>



-- 
Kind regards Nick




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux