Fortran and cpp option : How to protect a comma?

An option is defined (value = 1 or 2) to chose between two instructions and I would like to use with an instruction which have a comma.

#define option 1

#if option == 1
#define my_instr(instr1, instr2) instr1
#else if option == 2
#define my_instr(instr1, instr2) instr2
#endif

It works but when there is a comma in the instruction, I have a problem.

For example :

program main

 my_instr(print *,"opt 1", print * ,"opt 2")

end program main

does not compile (gftran -cpp) : Too much args. I am ok.

Thus, to escape the comma, parentheses are added : my_instr((print *,"opt 1"), (print * ,"opt 2"))

But it does not compile any more because of parentheses.

How can I solve that ?



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations