0

Currently, I am digging myself through some "modern" 2003 Fortran code and stumbled onto the concept of macros (which they "recently" added) with which I am not familiar with.

  • Can you give a concise description of what a macro does?

  • What is its typical use cases?

An example snipper of the code looks like the following. It seems to be handling some preprocessing and is part of an header (*.h) file.

#ifdef _VECTORIZED_DIMENSION_INDEX_
#  define _DIMENSION_EXT_SLICE_ ,dimension(loop_start:)
#else
#  define _DIMENSION_EXT_SLICE_
#endif
465b
  • 1,047
  • 1
  • 13
  • 25
  • Outside of pre-processing (which is not part of the Fortran language) I can not think what you mean by this. Can you provide an example, please? – Ian Bush Feb 11 '20 at 11:37
  • As far as I understand, they are used for preprocessing purposes. I edited the questions to provide an example. – 465b Feb 11 '20 at 12:49
  • 1
    The macros you show are CPP macros. They follow the C-preprocessor syntax (with some minor modifications - in gfortran they follow the so-called traditional style C macros). There are no standard Fortran macros (ignoring the abandoned coco). You can read loads of information about it here in the [tag:cpp] and [tag:macros] tags. The macros were never (not even recently) added to Fortran and are not part of modern Fortran. – Vladimir F Героям слава Feb 11 '20 at 13:02
  • Why do I have cpp macros in a, besides that,"pure" fortran code, and why does this work? This has to imply strong compiler decencies, doesn't it? – 465b Feb 11 '20 at 13:07
  • 1
    The Fortran compiler authors supply, as a completely non-standard extension, the C preprocessor. For Gfortran it is the actual `cpp`, the very same preprocessor that is used for C and C++. Other compilers use a slightly modified `fpp`. Some may not support the macros at all. Why would you use them? - see the link given and other questions like https://stackoverflow.com/questions/41233923/conditional-compilation-in-gfortran https://stackoverflow.com/questions/44860277/how-to-get-a-module-with-different-type-for-code-reuse?rq=1 and follow the links in them. – Vladimir F Героям слава Feb 11 '20 at 13:09
  • 1
    If people think the question should be re-opened and the information moved there, please comment or vote for re-opening. I currently think the link answers the question well as they are really in-fact C macros and it would be hard to come up with all those interesting use cases again. – Vladimir F Героям слава Feb 11 '20 at 13:11

0 Answers0