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
  • 25,269
  • 4
  • 47
  • 72
ATK
  • 1,296
  • 10
  • 26

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
  • 25,269
  • 4
  • 47
  • 72
  • So if I say -DNBYTE=64 and add that flag while compiling the code, that will be it – ATK Mar 18 '19 at 10:25
  • @A2LBK For [`ifort`](https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-using-fortran-preprocessor-options) it is the same syntax – kvantour Mar 18 '19 at 10:28
  • @A2LBK yes, but you need to make sure your code is beeing preprocessed. – kvantour Mar 18 '19 at 10:28
  • Yes, I am doing this with the -fpp flag. Many thanks ! – ATK Mar 18 '19 at 10:34