What is the difference between COMPLEX(8) and COMPLEX*8?
BardiaMahjour 2700046684 Visits (6905)
In the Fortran language, the kind type parameter of an intrinsic type is specified between parenthesis following the intrinsic type keyword. For example if you declare a variable of type REAL(8), the variable will have a kind type parameter equal to 8 and it will occupy 8-bytes in memory. A variable of type COMPLEX consists of a real and an imaginary part. Both the real and the imaginary parts are of type REAL. By specifying the kind type parameter in a COMPLEX type declaration, you specify the kind type parameter of each part of the complex entity. For example in the following program:
complex(8) :: c print *, sizeof(c) end
the sizeof() function returns 16. This is because the real and the imaginary parts of c are each 8-bytes long, which adds up to 16 bytes.
As an IBM extension, XL Fortran allows you to provide the length specification instead of the kind type parameter. The length specification in a complex declaration specifies the length of the whole complex object. For example, variable c in the example above can also be declared as follows:
complex*16 :: c print *, sizeof(c) end
the sizeof() function returns 16 and the real and the imaginary parts of c are each 8-bytes long.
If complex*8 is used, the resulting variable c will be of a different size. For example:
complex*8 :: c print *, sizeof(c) endThe sizeof() funtion returns 8 and the real and the imaginary parts of c are each 4-bytes long.