2

I'm trying to add a suffix to the name of my subroutines, but I can't get the concatenation token of the C preprocessor to work properly. I have the following example:

test.f90:

#define ADD_SUFFIX(name) name##_r

subroutine ADD_SUFFIX(mysub)()
   print*,'Success'
end subroutine

program test
   implicit none
   call mysub_r()
end program

Then I run gfortran -cpp test.f90 -o test.x and get:

test.f90:3.16:
subroutine mysub##_r
           1
Error: Syntax error in SUBROUTINE statement at (1)

I'm not very experienced in using preprocessor directives and everywhere I looked I see people using the operator like that (see here for example). Why does it copy the "##" literally in my case and how can I fix it to add suffixes?

francescalus
  • 30,576
  • 16
  • 61
  • 96
Nordico
  • 1,226
  • 2
  • 15
  • 31
  • I didn't tag it as fortran because I thought the preprocessor directives should be independent on which language it is applied (not so the compiler used, hence the tag gfortran). However, you and @francescalus are right, the answer was in that other question, apologies for not finding it before. – Nordico Aug 08 '17 at 19:11
  • It is independent of the language if you call `cpp` directly. But if you call it through `gfortran` it behaves differently from being called from `gcc`. – Vladimir F Героям слава Aug 08 '17 at 20:38

0 Answers0