CPP / GPP in Fortran Variation Macro (plus Fortran // concatenation)

I am trying to compile a huge, world-famous numerical code for weather forecasting, written mainly in Fortran 90, which uses cpp extensively and works successfully with PGI, Intel and gfortran. Now I have inherited a version in which experts have added several hundred cases of variable macros. They use Intel and fpp, which are apparently a bit more Fortran-oriented and can make everything work. I need to use gfortran and I was not able to get cpp to work with this code with its new additions.

An important simplification of the problem is as follows:

Code for preprocessing:

    PRINT *, "Hello" // "Don"
#define adderv(...) (myadd(__VA_ARGS__))
    sumv = adderv(1, 2, 3, 4, 5)

Using cpp without an option -traditionalwill handle a variable macro, but not Fortran concatenation:

$ cpp -P t.F90
    PRINT *, "Hello"
    sumv = (myadd(1, 2, 3, 4, 5))

, -traditional , :

$ cpp -P -traditional t.F90 
t.F90:2:0: error: syntax error in macro parameter list
 #define adderv(...) (myadd(__VA_ARGS__))
 ^
    PRINT *, "Hello" // "Don"
    sumv = adderv(1, 2, 3, 4, 5)

.

gpp , , . ... __VA_ARGS__. , ...

    PRINT *, "Hello" // "Don"
#define adderv() (myadd(__VA_ARGS__))
    sumv = adderv(1, 2, 3, 4, 5)



$ gpp t.F90
    PRINT *, "Hello" // "Don"
    sumv = (myadd(__VA_ARGS__))

, , , , , Fortran . .

PRINT *, "Hello" // "Don"

PRINT *, "Hello" /&
&              / "Don"

cpp gpp , - , . , (, concat ) , .


- roygvib -C. , , Fortran C. , , , :

$ cat t.f90
        PRINT *, "Hello" // "Don"
    #define adderv(...) (myadd(__VA_ARGS__))
        sumv = adderv(1, 2, 3, 4, 5)

-P -C, , ++ ( Fortran concat), C-comment:

   $ /lib/cpp -P -C  t.F90
   /* Copyright (C) 1991-2014 Free Software Foundation, Inc.
      This file is part of the GNU C Library.
   .
   .
   .
   /* wchar_t uses ISO/IEC 10646 (2nd ed., published 2011-03-15) /       Unicode 6.0.  */
   /* We do not support C11 <threads.h>.  */
       PRINT *, "Hello" // "Don"
       sumv = (myadd(1, 2, 3, 4, 5))

( , cpp) , "" cpp.

, , script (, mycpp), cpp, , C, .

, , C-. , , , , , - C-.

- , , .

+4
1

, , , , cpp. , 4.8 C Fortran, , , . , cpp-4.7.

( Ubuntu 16.04) , .

sudo apt-get install cpp-4.7
put the necessary executable in /usr/bin/cpp-4.7

, .

$ /usr/bin/cpp-4.7 -C -P t.F90
    PRINT *, "Hello" // "Don"
    sum = (myadd(1, 2, 3, 4, 5))  
+1

Source: https://habr.com/ru/post/1664937/


All Articles