KIND declaration quirk in Fortran

Here’s another quirk I found about KIND declarations in Fortran. Here are two ways to declare the KIND of a variable:

COMPLEX*16 :: a
COMPLEX(KIND=8) :: b

Here’s the interesting part: both of these variables have the same KIND! They are both ‘double precision’, generally using 8 bytes of storage for each of the real and imaginary parts of the number, or 16 bytes total. I say ‘generally’ because this can be compiler specific. Check out the module ISO_FORTRAN_ENV for more portability.

Update (2012-06-19): I learned why there is a difference here. It turns out that the declaration complex*16 is not part of any Fortran standard. Instead, it is a vendor extension that is supported by most, if not all, compilers today. So if you compile with strict standards-checking like gfortran -std=f2008, then you will receive an error. The correct way to write it is with complex(KIND=8).

Leave a Reply

Your email address will not be published. Required fields are marked *

     

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>