Real & Integer

I’m working some legacy code, and just recently realized that there are many places in the code where integers are used where reals should be. e.g. :

real::varA, varB
varA =  10^18
varB =  10^18.0
print *, varA
print *, varB

yeilds:

0
1E-18

The above is just an example, but the original authors of the code meant for varA to be 1E-18 and not zero. And, this is affecting the results of the program.

Is there any compiler switch or any other way to either a) automatically cast integer constants up to reals ( e.g. 18 -> 18.0) or b) at least stop compilation with an error so that I can manually correct these lines?

Thanks.

HI LKP,

Just to clarify, I think you meant “10**18” not “10^18” since “10^18” is not legal syntax. Also, you should get a negative value for varA, not 0.

What’s happening is that the integer constant “1018" is too big for an INTEGER*4, which is the default, and thus results in a negative value. This negative value is then cast to a REAL and assigned to varA. For this test case you can compile with “-i8” which changes the default integer kind to 8, and will be big enough to hold "1018”. Of course, using “-i8” might cause other problems since all “INTEGER” variables will now be “INTEGER*8”, but it’s worth a try.

Hope this helps,
Mat