1

I want to align my data with !DIR$ ATTRIBUTES ALIGN:NBYTE::X where NBYTE is defined at compilation time. I am currently at the top of every source file have

 #ifndef NBYTE
  #define NBYTE 64
 #endif

However, I don't if I can define this only once I use the NBYTE variable everywhere. So my two questions are:

  1. Is it possible to define the macro only once and use it everywhere without including a file or the macro in each source file?

  2. Can I define the variable in the Makefile and use it in my Fortran code?

kvantour
  • 22,845
  • 4
  • 45
  • 58
A2LBK
  • 1,359
  • 4
  • 15

1 Answers1

3

Most compilers allow you to preprocess your source using a C-type preprocessor. Simultaneously, they allow you to pass preprocessor macros via command line of the compiler. In gfortran you can use the following syntax:

-Dname=definition: The contents of the definition are tokenized and processed as if they appeared during translation phase three in a #define directive. In particular, the definition will be truncated by embedded newline characters.

kvantour
  • 22,845
  • 4
  • 45
  • 58