Re: Preprocessing & concatenation

You might want to look at the M4 macro processor, it is purely
text-based (no C syntax recognized) and both simple and very powerful,
convenient for preprocessing Fortran. It should be available on
virtually any Unix-like system, and on any system that has GNU tools
installed. (It's part of the autoconf toolchain.)

-- Wolfgang

On 01/18/2011 05:26 PM, Jared Ahern wrote:
Hi all,

I know this has been discussed here before (the most recent thread
that I found was from 2008), but I'm trying to use the C preprocessor
in Fortran and have run into the problem that concatenation is
generally not supported in macro expansion. This is due in gfortran
at least to the compiler using cpp in "traditional" mode, which does
not include some features such as concatenation with the "##" macro

At present, I am attempting to greatly reduce code duplication by
essentially doing derived type templating using include files and
macro expansion. This necessitates macro concatenation to form
unquoted text like "FUNCTION Foo_TypeA", etc. Although it's
completely possible to write out all of the code by hand, it's length
makes it error-prone, and it may take substantially more time to
maintain. Currently I use gfortran, ifort, g95 and occasionally NAG,
so I would like a solution that is portable (and hopefully compatible
with Doxygen).

What workaround would people here propose? Perhaps:
1) A different cpp-traditional mechanism for concatenation?
2) Using COCO with macro extensions? I have not had experience with
it, opting so far for integrated prepossessing for convenience and
because this was at one time necessary for some external libraries.
Is it now recommended?
3) Generating the necessary code with Python before compile-time.
4) Other?


E-mail: firstnameinitial.lastname@xxxxxxxxx
Domain: yahoo

Relevant Pages