[FLASH-USERS] #define E problem

Klaus Weide klaus at flash.uchicago.edu
Mon Mar 16 15:07:50 EDT 2015


On Mon, 16 Mar 2015, Seyit Hocuk wrote:

> I haven't posted for a while, but I just came accross an interesting problem.
> The interesting part is that I did not have this issue in the past.
> 
> The number of electrons is defined as E (i.e., #define E 4) in Multispecies.h.
> Because of this, wherever I include this header file my exponent notation with
> capital E's are giving wrong numbers. For example 1.0E-24 gives -22.96 (that
> is 1.04 - 24) instead of 10^(-24) , while 1.0e-24 correctly results in the
> right number. If this is the expected behaviour, I find it illogical.

Seyit,

Yes this is ugly...
Something like '#define E 4' should not be in the code, in particular in 
a header file than can get included by arbitrary source files.

Suggestions for you -
1. Only include "Multispecies.h" where it is necessary.
   Avoid capital 'E' in numerical constants in those files.

2. Newer versions of FLASH have kept defining a symbol 'E' for backward
   compatibility, but have changed it to
      #define E (4)
   (note parentheses). This will at least result in a syntax error 
   when 'E' is used in a numerical constant, rather that a quiet 
   corruption of the value as in your case.


> I've succesfully reproduced this with most intel fortran compilers from 11.0
> to 14.0. I don't know why it appears now and did not in the past. The compiler
> flags -uppercase or -lowercase (or -name lowercase) do not help in this case.

I do not expct this behavior to depend on Fortran compiler version.
It could depend on the preprocessor used, but I expect the behavior to be 
the same with different proprocessor implementations. 

> My question is how do I avoid this problem without changing the definition,
> since I would have to change everywhere where the multispecies unit is used
> for electrons, or without manually changing my exponent notations to lower
> cases everywhere. Maybe the manual way isn't much work, but I don't want to
> search the whole code.

See above. 
Using the parenthesised version of the macro may help you find the 
occurrences where you need to change your exponent notation.

Klaus



More information about the flash-users mailing list